View Javadoc
1   /*
2    * Copyright 2002-2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * Unit tests for {@link ExtendedBeanInfoTests}.
28   *
29   * @author Chris Beams
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  }