1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.springframework.beans;
18
19 import java.beans.IntrospectionException;
20
21 import org.junit.Test;
22
23 import static org.hamcrest.CoreMatchers.*;
24 import static org.junit.Assert.*;
25
26
27
28
29
30
31 public class ExtendedBeanInfoFactoryTests {
32
33 private ExtendedBeanInfoFactory factory = new ExtendedBeanInfoFactory();
34
35 @Test
36 public void shouldNotSupportClassHavingOnlyVoidReturningSetter() throws IntrospectionException {
37 @SuppressWarnings("unused")
38 class C {
39 public void setFoo(String s) { }
40 }
41 assertThat(factory.getBeanInfo(C.class), nullValue());
42 }
43
44 @Test
45 public void shouldSupportClassHavingNonVoidReturningSetter() throws IntrospectionException {
46 @SuppressWarnings("unused")
47 class C {
48 public C setFoo(String s) { return this; }
49 }
50 assertThat(factory.getBeanInfo(C.class), notNullValue());
51 }
52
53 @Test
54 public void shouldSupportClassHavingNonVoidReturningIndexedSetter() throws IntrospectionException {
55 @SuppressWarnings("unused")
56 class C {
57 public C setFoo(int i, String s) { return this; }
58 }
59 assertThat(factory.getBeanInfo(C.class), notNullValue());
60 }
61
62 @Test
63 public void shouldNotSupportClassHavingNonPublicNonVoidReturningIndexedSetter() throws IntrospectionException {
64 @SuppressWarnings("unused")
65 class C {
66 void setBar(String s) { }
67 }
68 assertThat(factory.getBeanInfo(C.class), nullValue());
69 }
70
71 @Test
72 public void shouldNotSupportClassHavingNonVoidReturningParameterlessSetter() throws IntrospectionException {
73 @SuppressWarnings("unused")
74 class C {
75 C setBar() { return this; }
76 }
77 assertThat(factory.getBeanInfo(C.class), nullValue());
78 }
79
80 @Test
81 public void shouldNotSupportClassHavingNonVoidReturningMethodNamedSet() throws IntrospectionException {
82 @SuppressWarnings("unused")
83 class C {
84 C set(String s) { return this; }
85 }
86 assertThat(factory.getBeanInfo(C.class), nullValue());
87 }
88
89 }