Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELDX-181 enforce JavaBean conventions
- enforce the JavaBean conventions when creating a property from a method - write tests to validate that method is handled propertly - include reference to JavaBean spec document
- Loading branch information
1 parent
9ed717a
commit 6337448
Showing
4 changed files
with
232 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
impl/src/test/java/org/jboss/weld/extensions/test/properties/ClassToIntrospect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package org.jboss.weld.extensions.test.properties; | ||
|
||
import java.net.URL; | ||
|
||
public class ClassToIntrospect | ||
{ | ||
private String name; | ||
|
||
private String p; | ||
|
||
private URL URL; | ||
|
||
public String getName() | ||
{ | ||
return name; | ||
} | ||
|
||
public void setName(String name) | ||
{ | ||
this.name = name; | ||
} | ||
|
||
public String getP() | ||
{ | ||
return p; | ||
} | ||
|
||
public void setP(String p) | ||
{ | ||
this.p = p; | ||
} | ||
|
||
public String getTitle() | ||
{ | ||
return "Hero"; | ||
} | ||
|
||
public String get() | ||
{ | ||
return null; | ||
} | ||
|
||
public boolean is() | ||
{ | ||
return false; | ||
} | ||
|
||
public void getFooBar() | ||
{ | ||
} | ||
|
||
public void setSalary(Double base, Double bonus) | ||
{ | ||
} | ||
|
||
public URL getURL() | ||
{ | ||
return URL; | ||
} | ||
|
||
public void setURL(URL URL) | ||
{ | ||
this.URL = URL; | ||
} | ||
|
||
public Boolean isValid() | ||
{ | ||
return false; | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
impl/src/test/java/org/jboss/weld/extensions/test/properties/PropertyFromMethodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package org.jboss.weld.extensions.test.properties; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.lang.reflect.Method; | ||
import java.net.URL; | ||
|
||
import org.jboss.weld.extensions.properties.Properties; | ||
import org.jboss.weld.extensions.properties.Property; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Verify that only valid properties are permitted, as per the JavaBean specification. | ||
* | ||
* @author Dan Allen | ||
* @see http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html | ||
*/ | ||
public class PropertyFromMethodTest | ||
{ | ||
@Test | ||
public void testValidPropertyGetterMethod() throws Exception | ||
{ | ||
Method getter = ClassToIntrospect.class.getMethod("getName"); | ||
Property<String> p = Properties.createProperty(getter); | ||
assertNotNull(p); | ||
assertEquals("name", p.getName()); | ||
assertEquals(getter, p.getMember()); | ||
} | ||
|
||
@Test | ||
public void testValidPropertySetterMethod() throws Exception | ||
{ | ||
Property<String> p = Properties.createProperty(ClassToIntrospect.class.getMethod("setName", String.class)); | ||
assertNotNull(p); | ||
assertEquals("name", p.getName()); | ||
} | ||
|
||
@Test | ||
public void testReadOnlyProperty() throws Exception | ||
{ | ||
Property<String> p = Properties.createProperty(ClassToIntrospect.class.getMethod("getTitle")); | ||
assertNotNull(p); | ||
assertEquals("title", p.getName()); | ||
assertTrue(p.isReadOnly()); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testEmptyPropertyGetterMethod() throws Exception | ||
{ | ||
Properties.createProperty(ClassToIntrospect.class.getMethod("get")); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testEmptyBooleanPropertyGetterMethod() throws Exception | ||
{ | ||
Properties.createProperty(ClassToIntrospect.class.getMethod("is")); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testNonPrimitiveBooleanPropertyIsMethod() throws Exception | ||
{ | ||
Properties.createProperty(ClassToIntrospect.class.getMethod("isValid")); | ||
} | ||
|
||
@Test | ||
public void testSingleCharPropertyGetterMethod() throws Exception | ||
{ | ||
Method getter = ClassToIntrospect.class.getMethod("getP"); | ||
Property<String> p = Properties.createProperty(getter); | ||
assertNotNull(p); | ||
assertEquals("p", p.getName()); | ||
assertEquals(getter, p.getMember()); | ||
} | ||
|
||
@Test | ||
public void testSingleCharPropertySetterMethod() throws Exception | ||
{ | ||
Property<String> p = Properties.createProperty(ClassToIntrospect.class.getMethod("setP", String.class)); | ||
assertNotNull(p); | ||
assertEquals("p", p.getName()); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testGetterMethodWithVoidReturnType() throws Exception | ||
{ | ||
Properties.createProperty(ClassToIntrospect.class.getMethod("getFooBar")); | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testSetterMethodWithMultipleParameters() throws Exception | ||
{ | ||
Properties.createProperty(ClassToIntrospect.class.getMethod("setSalary", Double.class, Double.class)); | ||
} | ||
|
||
@Test | ||
public void testAcronymProperty() throws Exception | ||
{ | ||
Method getter = ClassToIntrospect.class.getMethod("getURL"); | ||
Property<URL> p = Properties.createProperty(getter); | ||
assertNotNull(p); | ||
assertEquals("URL", p.getName()); | ||
assertEquals(getter, p.getMember()); | ||
} | ||
} |