01: package net.sf.mockcreator.expectable;
02:
03: import net.sf.mockcreator.TestCase;
04:
05: public class ExpectJavaBeanTest extends TestCase {
06:
07: static class A {
08: public String foo;
09:
10: public String getFoo() {
11: return foo;
12: }
13: }
14:
15: static class B extends A {
16: public boolean bar;
17:
18: public boolean isBar() {
19: return bar;
20: }
21: }
22:
23: static class C extends A {
24: public boolean bar;
25:
26: public boolean isBar() {
27: return bar;
28: }
29:
30: protected boolean isBaz() {
31: return bar;
32: }
33:
34: private long getX() {
35: return 0;
36: }
37:
38: static public char getN() {
39: return 'N';
40: }
41: }
42:
43: public void testNormal() {
44: assertTrue(new ExpectJavaBean(null).isExpected(null));
45:
46: A a1 = new A();
47: assertTrue(new ExpectJavaBean(a1).isExpected(a1));
48: assertFalse(new ExpectJavaBean(null).isExpected(a1));
49: assertFalse(new ExpectJavaBean(a1).isExpected(null));
50:
51: a1.foo = "foo";
52: assertTrue(new ExpectJavaBean(a1).isExpected(a1));
53:
54: A a2 = new A();
55: assertFalse(new ExpectJavaBean(a1).isExpected(a2));
56:
57: a2.foo = "foo";
58: assertTrue(new ExpectJavaBean(a1).isExpected(a2));
59: }
60:
61: public void testSubclasses() {
62: B b1 = new B();
63: B b2 = new B();
64: assertTrue(new ExpectJavaBean(b1).isExpected(b1));
65: assertFalse(new ExpectJavaBean(b1).isExpected(new A()));
66:
67: b1.bar = true;
68: assertFalse(new ExpectJavaBean(b1).isExpected(b2));
69: b2.foo = "xxx";
70: assertFalse(new ExpectJavaBean(b1).isExpected(b2));
71: b2.bar = true;
72: assertFalse(new ExpectJavaBean(b1).isExpected(b2));
73: b1.foo = "xxx";
74: assertTrue(new ExpectJavaBean(b1).isExpected(b2));
75: }
76:
77: public void testTypes() {
78: B b1 = new B();
79: C c2 = new C();
80: assertTrue(new ExpectJavaBean(c2).isExpected(b1));
81: assertTrue(new ExpectJavaBean(b1).isExpected(c2));
82:
83: b1.bar = true;
84: b1.foo = "xxx";
85:
86: c2.foo = "xxx";
87: c2.bar = true;
88:
89: assertTrue(new ExpectJavaBean(c2).isExpected(b1));
90: assertTrue(new ExpectJavaBean(b1).isExpected(c2));
91: }
92: }
|