-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
225 additions
and
32 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
92 changes: 92 additions & 0 deletions
92
.../java/net/karneim/pojobuilder/analysis/with/setter/JavaModelAnalyzer_WithSetter_Test.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,92 @@ | ||
package net.karneim.pojobuilder.analysis.with.setter; | ||
|
||
import static javax.lang.model.element.Modifier.PUBLIC; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.Test; | ||
|
||
import net.karneim.pojobuilder.analysis.Input; | ||
import net.karneim.pojobuilder.analysis.Output; | ||
import net.karneim.pojobuilder.analysis.with.AnalysisTestSupport; | ||
import net.karneim.pojobuilder.model.PropertyListM.Key; | ||
import net.karneim.pojobuilder.model.PropertyM; | ||
|
||
public class JavaModelAnalyzer_WithSetter_Test extends AnalysisTestSupport { | ||
|
||
@Test | ||
public void testAnalyze_public_void_setMyProperty_Object() { | ||
// Given: | ||
Class<?> pojoClass = PojoWithPublicVoidObjectSetter.class; | ||
Input input = inputFor(pojoClass); | ||
// When: | ||
Output output = underTest.analyze(input); | ||
// Then: | ||
assertThat(output).isNotNull(); | ||
Key key = new Key("myProperty", "java.lang.Object"); | ||
PropertyM property = output.getBuilderModel().getProperties().get(key); | ||
assertThat(property).isNotNull(); | ||
assertThat(property.getSetterMethod()).isNotNull(); | ||
assertThat(property.getSetterMethod().getDeclaringClass().getName()) | ||
.isEqualTo(pojoClass.getName()); | ||
assertThat(property.getSetterMethod().getModifiers()).containsOnly(PUBLIC); | ||
assertThat(property.getSetterMethod().getName()).isEqualTo("setMyProperty"); | ||
} | ||
|
||
@Test | ||
public void testAnalyze_public_void_setMyProperty_primitive() { | ||
// Given: | ||
Class<?> pojoClass = PojoWithPublicVoidPrimitiveSetter.class; | ||
Input input = inputFor(pojoClass); | ||
// When: | ||
Output output = underTest.analyze(input); | ||
// Then: | ||
assertThat(output).isNotNull(); | ||
Key key = new Key("myProperty", "int"); | ||
PropertyM property = output.getBuilderModel().getProperties().get(key); | ||
assertThat(property).isNotNull(); | ||
assertThat(property.getSetterMethod()).isNotNull(); | ||
assertThat(property.getSetterMethod().getDeclaringClass().getName()) | ||
.isEqualTo(pojoClass.getName()); | ||
assertThat(property.getSetterMethod().getModifiers()).containsOnly(PUBLIC); | ||
assertThat(property.getSetterMethod().getName()).isEqualTo("setMyProperty"); | ||
} | ||
|
||
@Test | ||
public void testAnalyze_public_Object_setMyProperty_Object() { | ||
// Given: | ||
Class<?> pojoClass = PojoWithPublicObjectObjectSetter.class; | ||
Input input = inputFor(pojoClass); | ||
// When: | ||
Output output = underTest.analyze(input); | ||
// Then: | ||
assertThat(output).isNotNull(); | ||
Key key = new Key("myProperty", "java.lang.Object"); | ||
PropertyM property = output.getBuilderModel().getProperties().get(key); | ||
assertThat(property).isNotNull(); | ||
assertThat(property.getSetterMethod()).isNotNull(); | ||
assertThat(property.getSetterMethod().getDeclaringClass().getName()) | ||
.isEqualTo(pojoClass.getName()); | ||
assertThat(property.getSetterMethod().getModifiers()).containsOnly(PUBLIC); | ||
assertThat(property.getSetterMethod().getName()).isEqualTo("setMyProperty"); | ||
} | ||
|
||
@Test | ||
public void testAnalyze_public_primitive_setMyProperty_Object() { | ||
// Given: | ||
Class<?> pojoClass = PojoWithPublicPrimitiveObjectSetter.class; | ||
Input input = inputFor(pojoClass); | ||
// When: | ||
Output output = underTest.analyze(input); | ||
// Then: | ||
assertThat(output).isNotNull(); | ||
Key key = new Key("myProperty", "java.lang.Object"); | ||
PropertyM property = output.getBuilderModel().getProperties().get(key); | ||
assertThat(property).isNotNull(); | ||
assertThat(property.getSetterMethod()).isNotNull(); | ||
assertThat(property.getSetterMethod().getDeclaringClass().getName()) | ||
.isEqualTo(pojoClass.getName()); | ||
assertThat(property.getSetterMethod().getModifiers()).containsOnly(PUBLIC); | ||
assertThat(property.getSetterMethod().getName()).isEqualTo("setMyProperty"); | ||
} | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...a/java/net/karneim/pojobuilder/analysis/with/setter/PojoWithPublicObjectObjectSetter.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,10 @@ | ||
package net.karneim.pojobuilder.analysis.with.setter; | ||
|
||
import net.karneim.pojobuilder.GeneratePojoBuilder; | ||
|
||
@GeneratePojoBuilder | ||
public class PojoWithPublicObjectObjectSetter { | ||
public Object setMyProperty(Object myProperty) { | ||
return null; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ava/net/karneim/pojobuilder/analysis/with/setter/PojoWithPublicPrimitiveObjectSetter.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,10 @@ | ||
package net.karneim.pojobuilder.analysis.with.setter; | ||
|
||
import net.karneim.pojobuilder.GeneratePojoBuilder; | ||
|
||
@GeneratePojoBuilder | ||
public class PojoWithPublicPrimitiveObjectSetter { | ||
public int setMyProperty(Object myProperty) { | ||
return 0; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ata/java/net/karneim/pojobuilder/analysis/with/setter/PojoWithPublicVoidObjectSetter.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,8 @@ | ||
package net.karneim.pojobuilder.analysis.with.setter; | ||
|
||
import net.karneim.pojobuilder.GeneratePojoBuilder; | ||
|
||
@GeneratePojoBuilder | ||
public class PojoWithPublicVoidObjectSetter { | ||
public void setMyProperty(Object myProperty) {} | ||
} |
8 changes: 8 additions & 0 deletions
8
.../java/net/karneim/pojobuilder/analysis/with/setter/PojoWithPublicVoidPrimitiveSetter.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,8 @@ | ||
package net.karneim.pojobuilder.analysis.with.setter; | ||
|
||
import net.karneim.pojobuilder.GeneratePojoBuilder; | ||
|
||
@GeneratePojoBuilder | ||
public class PojoWithPublicVoidPrimitiveSetter { | ||
public void setMyProperty(int myProperty) {} | ||
} |
Oops, something went wrong.