1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.yaml.snakeyaml.constructor;
18
19 import java.io.IOException;
20 import java.util.Date;
21
22 import junit.framework.TestCase;
23
24 import org.yaml.snakeyaml.Yaml;
25
26 public class MockDateBeanConstructorTest extends TestCase {
27
28 public void testConstructor() throws IOException {
29 String className = "!!org.yaml.snakeyaml.constructor.MockDateBeanConstructorTest$DateBean {number: 24, date: 2009-07-24}";
30 Yaml yaml = new Yaml();
31 try {
32 yaml.load(className);
33 fail("MockDate cannot be constructed.");
34 } catch (Exception e) {
35 assertEquals(
36 "Cannot create property=date for JavaBean=<DateBean n=24>; Cannot construct: 'class org.yaml.snakeyaml.constructor.MockDateBeanConstructorTest$MockDate'",
37 e.getCause().getMessage());
38 }
39 }
40
41 public static class DateBean {
42 private int number;
43 private MockDate date;
44
45 public int getNumber() {
46 return number;
47 }
48
49 public void setNumber(int number) {
50 this.number = number;
51 }
52
53 public MockDate getDate() {
54 return date;
55 }
56
57 public void setDate(MockDate date) {
58 this.date = date;
59 }
60
61 @Override
62 public String toString() {
63 return "<DateBean n=" + number + ">";
64 }
65 }
66
67 public static class MockDate extends Date {
68 private static final long serialVersionUID = 621384692653658062L;
69
70 public MockDate(long date) {
71 throw new RuntimeException("Test error.");
72 }
73 }
74 }