From 7bee304a3e2757d1a0fbcddff88b9ccffb6545e7 Mon Sep 17 00:00:00 2001 From: Artyom Kozhemyakin Date: Sun, 8 Nov 2015 18:30:56 +0300 Subject: [PATCH 1/3] Update tests to actualy cover each individual case The problem with current version of the test suite is that it actualy covers only first test executed. The reason is all test cases use the same set of configuration parameters (test.*). After the first test gets executed, all configuration parameters are already bound. It leads to a situation when all following tests become nearly useless. This goal of this commit is to provide separate data set to each test case (pojo via constructor, pojo via fields, pojo via methods and provided pojo). --- .../racc/tscg/TypesafeConfigModuleTest.java | 42 +++++++++--------- .../tscg/test/ConstructorInjectedPojo.java | 44 +++++++++---------- .../racc/tscg/test/FieldInjectedPojo.java | 42 +++++++++--------- .../racc/tscg/test/MethodInjectedPojo.java | 42 +++++++++--------- src/test/resources/conf/test.conf | 7 ++- 5 files changed, 91 insertions(+), 86 deletions(-) diff --git a/src/test/java/com/github/racc/tscg/TypesafeConfigModuleTest.java b/src/test/java/com/github/racc/tscg/TypesafeConfigModuleTest.java index e3d167a..55f382b 100644 --- a/src/test/java/com/github/racc/tscg/TypesafeConfigModuleTest.java +++ b/src/test/java/com/github/racc/tscg/TypesafeConfigModuleTest.java @@ -45,27 +45,27 @@ protected void configure() { @Provides @Singleton ProvidedPojo providePojo( - @TypesafeConfig("test.boolean") boolean testBoolean, - @TypesafeConfig("test.yesBoolean") boolean testYesBoolean, - @TypesafeConfig("test.long") long testLong, - @TypesafeConfig("test.byte") byte testByte, - @TypesafeConfig("test.int") int testInt, - @TypesafeConfig("test.double") double testDouble, - @TypesafeConfig("test.float") float testFloat, - @TypesafeConfig("test.string") String testString, - @TypesafeConfig("test.list.boolean") List testListOfBoolean, - @TypesafeConfig("test.list.integer") List testListOfInteger, - @TypesafeConfig("test.list.double") List testListOfDouble, - @TypesafeConfig("test.list.long") List testListOfLong, - @TypesafeConfig("test.list.string") List testListOfString, - @TypesafeConfig("test.list.duration") List testListOfDuration, - @TypesafeConfig("test.list.size") List testListOfSize, - @TypesafeConfig("test.list.nested") List testListOfNested, - @TypesafeConfig("test.duration") Duration testDuration, - @TypesafeConfig("test.size") ConfigMemorySize testSize, - @TypesafeConfig("test.map") Map testMap, - @TypesafeConfig("test.map.intkey") Map testMapIntkey, - @TypesafeConfig("test.nested") NestedPojo testNestedPojo + @TypesafeConfig("provided.boolean") boolean testBoolean, + @TypesafeConfig("provided.yesBoolean") boolean testYesBoolean, + @TypesafeConfig("provided.long") long testLong, + @TypesafeConfig("provided.byte") byte testByte, + @TypesafeConfig("provided.int") int testInt, + @TypesafeConfig("provided.double") double testDouble, + @TypesafeConfig("provided.float") float testFloat, + @TypesafeConfig("provided.string") String testString, + @TypesafeConfig("provided.list.boolean") List testListOfBoolean, + @TypesafeConfig("provided.list.integer") List testListOfInteger, + @TypesafeConfig("provided.list.double") List testListOfDouble, + @TypesafeConfig("provided.list.long") List testListOfLong, + @TypesafeConfig("provided.list.string") List testListOfString, + @TypesafeConfig("provided.list.duration") List testListOfDuration, + @TypesafeConfig("provided.list.size") List testListOfSize, + @TypesafeConfig("provided.list.nested") List testListOfNested, + @TypesafeConfig("provided.duration") Duration testDuration, + @TypesafeConfig("provided.size") ConfigMemorySize testSize, + @TypesafeConfig("provided.map") Map testMap, + @TypesafeConfig("provided.map.intkey") Map testMapIntkey, + @TypesafeConfig("provided.nested") NestedPojo testNestedPojo ) { return new ProvidedPojo(testBoolean, testYesBoolean, testLong, testByte, testInt, testDouble, testFloat, testString, testListOfBoolean, testListOfInteger, testListOfDouble, testListOfLong, testListOfString, testListOfDuration, testListOfSize, testListOfNested, testDuration, testSize, testMap, testMapIntkey, testNestedPojo); } diff --git a/src/test/java/com/github/racc/tscg/test/ConstructorInjectedPojo.java b/src/test/java/com/github/racc/tscg/test/ConstructorInjectedPojo.java index fbffe14..a116694 100644 --- a/src/test/java/com/github/racc/tscg/test/ConstructorInjectedPojo.java +++ b/src/test/java/com/github/racc/tscg/test/ConstructorInjectedPojo.java @@ -36,28 +36,28 @@ public class ConstructorInjectedPojo implements TestPojo { @Inject public ConstructorInjectedPojo( - @TypesafeConfig("test.boolean") boolean testBoolean, - @TypesafeConfig("test.boolean") boolean testBooleanAgain, - @TypesafeConfig("test.yesBoolean") boolean testYesBoolean, - @TypesafeConfig("test.long") long testLong, - @TypesafeConfig("test.byte") byte testByte, - @TypesafeConfig("test.int") int testInt, - @TypesafeConfig("test.double") double testDouble, - @TypesafeConfig("test.float") float testFloat, - @TypesafeConfig("test.string") String testString, - @TypesafeConfig("test.list.boolean") List testListOfBoolean, - @TypesafeConfig("test.list.integer") List testListOfInteger, - @TypesafeConfig("test.list.double") List testListOfDouble, - @TypesafeConfig("test.list.long") List testListOfLong, - @TypesafeConfig("test.list.string") List testListOfString, - @TypesafeConfig("test.list.duration") List testListOfDuration, - @TypesafeConfig("test.list.size") List testListOfSize, - @TypesafeConfig("test.list.nested") List testListOfNested, - @TypesafeConfig("test.duration") Duration testDuration, - @TypesafeConfig("test.size") ConfigMemorySize testSize, - @TypesafeConfig("test.map") Map testMap, - @TypesafeConfig("test.map.intkey") Map testMapIntkey, - @TypesafeConfig("test.nested") NestedPojo testNestedPojo + @TypesafeConfig("constructor.boolean") boolean testBoolean, + @TypesafeConfig("constructor.boolean") boolean testBooleanAgain, + @TypesafeConfig("constructor.yesBoolean") boolean testYesBoolean, + @TypesafeConfig("constructor.long") long testLong, + @TypesafeConfig("constructor.byte") byte testByte, + @TypesafeConfig("constructor.int") int testInt, + @TypesafeConfig("constructor.double") double testDouble, + @TypesafeConfig("constructor.float") float testFloat, + @TypesafeConfig("constructor.string") String testString, + @TypesafeConfig("constructor.list.boolean") List testListOfBoolean, + @TypesafeConfig("constructor.list.integer") List testListOfInteger, + @TypesafeConfig("constructor.list.double") List testListOfDouble, + @TypesafeConfig("constructor.list.long") List testListOfLong, + @TypesafeConfig("constructor.list.string") List testListOfString, + @TypesafeConfig("constructor.list.duration") List testListOfDuration, + @TypesafeConfig("constructor.list.size") List testListOfSize, + @TypesafeConfig("constructor.list.nested") List testListOfNested, + @TypesafeConfig("constructor.duration") Duration testDuration, + @TypesafeConfig("constructor.size") ConfigMemorySize testSize, + @TypesafeConfig("constructor.map") Map testMap, + @TypesafeConfig("constructor.map.intkey") Map testMapIntkey, + @TypesafeConfig("constructor.nested") NestedPojo testNestedPojo ) { this.testBoolean = testBoolean; this.testYesBoolean = testYesBoolean; diff --git a/src/test/java/com/github/racc/tscg/test/FieldInjectedPojo.java b/src/test/java/com/github/racc/tscg/test/FieldInjectedPojo.java index b747617..a97817a 100644 --- a/src/test/java/com/github/racc/tscg/test/FieldInjectedPojo.java +++ b/src/test/java/com/github/racc/tscg/test/FieldInjectedPojo.java @@ -12,27 +12,27 @@ @Singleton public class FieldInjectedPojo implements TestPojo { - @Inject @TypesafeConfig("test.boolean") boolean testBoolean; - @Inject @TypesafeConfig("test.yesBoolean") boolean testYesBoolean; - @Inject @TypesafeConfig("test.long") long testLong; - @Inject @TypesafeConfig("test.byte") byte testByte; - @Inject @TypesafeConfig("test.int") int testInt; - @Inject @TypesafeConfig("test.double") double testDouble; - @Inject @TypesafeConfig("test.float") float testFloat; - @Inject @TypesafeConfig("test.string") String testString; - @Inject @TypesafeConfig("test.list.boolean") List testListOfBoolean; - @Inject @TypesafeConfig("test.list.integer") List testListOfInteger; - @Inject @TypesafeConfig("test.list.double") List testListOfDouble; - @Inject @TypesafeConfig("test.list.long") List testListOfLong; - @Inject @TypesafeConfig("test.list.string") List testListOfString; - @Inject @TypesafeConfig("test.list.duration") List testListOfDuration; - @Inject @TypesafeConfig("test.list.size") List testListOfSize; - @Inject @TypesafeConfig("test.list.nested") List testListOfNested; - @Inject @TypesafeConfig("test.duration") Duration testDuration; - @Inject @TypesafeConfig("test.size") ConfigMemorySize testSize; - @Inject @TypesafeConfig("test.map") Map testMap; - @Inject @TypesafeConfig("test.map.intkey") Map testMapIntkey; - @Inject @TypesafeConfig("test.nested") NestedPojo testNestedPojo; + @Inject @TypesafeConfig("field.boolean") boolean testBoolean; + @Inject @TypesafeConfig("field.yesBoolean") boolean testYesBoolean; + @Inject @TypesafeConfig("field.long") long testLong; + @Inject @TypesafeConfig("field.byte") byte testByte; + @Inject @TypesafeConfig("field.int") int testInt; + @Inject @TypesafeConfig("field.double") double testDouble; + @Inject @TypesafeConfig("field.float") float testFloat; + @Inject @TypesafeConfig("field.string") String testString; + @Inject @TypesafeConfig("field.list.boolean") List testListOfBoolean; + @Inject @TypesafeConfig("field.list.integer") List testListOfInteger; + @Inject @TypesafeConfig("field.list.double") List testListOfDouble; + @Inject @TypesafeConfig("field.list.long") List testListOfLong; + @Inject @TypesafeConfig("field.list.string") List testListOfString; + @Inject @TypesafeConfig("field.list.duration") List testListOfDuration; + @Inject @TypesafeConfig("field.list.size") List testListOfSize; + @Inject @TypesafeConfig("field.list.nested") List testListOfNested; + @Inject @TypesafeConfig("field.duration") Duration testDuration; + @Inject @TypesafeConfig("field.size") ConfigMemorySize testSize; + @Inject @TypesafeConfig("field.map") Map testMap; + @Inject @TypesafeConfig("field.map.intkey") Map testMapIntkey; + @Inject @TypesafeConfig("field.nested") NestedPojo testNestedPojo; public void setTestBoolean(boolean testBoolean) { this.testBoolean = testBoolean; diff --git a/src/test/java/com/github/racc/tscg/test/MethodInjectedPojo.java b/src/test/java/com/github/racc/tscg/test/MethodInjectedPojo.java index f881b9a..2829d16 100644 --- a/src/test/java/com/github/racc/tscg/test/MethodInjectedPojo.java +++ b/src/test/java/com/github/racc/tscg/test/MethodInjectedPojo.java @@ -35,107 +35,107 @@ public class MethodInjectedPojo implements TestPojo { private NestedPojo testNestedPojo; @Inject - public void setTestYesBoolean(@TypesafeConfig("test.boolean") boolean testYesBoolean) { + public void setTestYesBoolean(@TypesafeConfig("method.boolean") boolean testYesBoolean) { this.testYesBoolean = testYesBoolean; } @Inject - public void setTestLong(@TypesafeConfig("test.long") long testLong) { + public void setTestLong(@TypesafeConfig("method.long") long testLong) { this.testLong = testLong; } @Inject - public void setTestByte(@TypesafeConfig("test.byte") byte testByte) { + public void setTestByte(@TypesafeConfig("method.byte") byte testByte) { this.testByte = testByte; } @Inject - public void setTestInt(@TypesafeConfig("test.int") int testInt) { + public void setTestInt(@TypesafeConfig("method.int") int testInt) { this.testInt = testInt; } @Inject - public void setTestDouble(@TypesafeConfig("test.double") double testDouble) { + public void setTestDouble(@TypesafeConfig("method.double") double testDouble) { this.testDouble = testDouble; } @Inject - public void setTestFloat(@TypesafeConfig("test.float") float testFloat) { + public void setTestFloat(@TypesafeConfig("method.float") float testFloat) { this.testFloat = testFloat; } @Inject - public void setTestString(@TypesafeConfig("test.string") String testString) { + public void setTestString(@TypesafeConfig("method.string") String testString) { this.testString = testString; } @Inject - public void setTestListOfBoolean(@TypesafeConfig("test.list.boolean") List testListOfBoolean) { + public void setTestListOfBoolean(@TypesafeConfig("method.list.boolean") List testListOfBoolean) { this.testListOfBoolean = testListOfBoolean; } @Inject - public void setTestListOfInteger(@TypesafeConfig("test.list.integer") List testListOfInteger) { + public void setTestListOfInteger(@TypesafeConfig("method.list.integer") List testListOfInteger) { this.testListOfInteger = testListOfInteger; } @Inject - public void setTestListOfDouble(@TypesafeConfig("test.list.double") List testListOfDouble) { + public void setTestListOfDouble(@TypesafeConfig("method.list.double") List testListOfDouble) { this.testListOfDouble = testListOfDouble; } @Inject - public void setTestListOfLong(@TypesafeConfig("test.list.long") List testListOfLong) { + public void setTestListOfLong(@TypesafeConfig("method.list.long") List testListOfLong) { this.testListOfLong = testListOfLong; } @Inject - public void setTestListOfString(@TypesafeConfig("test.list.string") List testListOfString) { + public void setTestListOfString(@TypesafeConfig("method.list.string") List testListOfString) { this.testListOfString = testListOfString; } @Inject - public void setTestListOfDuration(@TypesafeConfig("test.list.duration") List testListOfDuration) { + public void setTestListOfDuration(@TypesafeConfig("method.list.duration") List testListOfDuration) { this.testListOfDuration = testListOfDuration; } @Inject - public void setTestListOfSize(@TypesafeConfig("test.list.size") List testListOfSize) { + public void setTestListOfSize(@TypesafeConfig("method.list.size") List testListOfSize) { this.testListOfSize = testListOfSize; } @Inject - public void setTestListOfNested(@TypesafeConfig("test.list.nested") List testListOfNested) { + public void setTestListOfNested(@TypesafeConfig("method.list.nested") List testListOfNested) { this.testListOfNested = testListOfNested; } @Inject - public void setTestDuration(@TypesafeConfig("test.duration") Duration testDuration) { + public void setTestDuration(@TypesafeConfig("method.duration") Duration testDuration) { this.testDuration = testDuration; } @Inject - public void setTestSize(@TypesafeConfig("test.size") ConfigMemorySize testSize) { + public void setTestSize(@TypesafeConfig("method.size") ConfigMemorySize testSize) { this.testSize = testSize; } @Inject - public void setTestMap(@TypesafeConfig("test.map") Map testMap) { + public void setTestMap(@TypesafeConfig("method.map") Map testMap) { this.testMap = testMap; } @Inject - public void setTestMapIntkey(@TypesafeConfig("test.map.intkey") Map testMapIntkey) { + public void setTestMapIntkey(@TypesafeConfig("method.map.intkey") Map testMapIntkey) { this.testMapIntkey = testMapIntkey; } @Inject - public void setTestNestedPojo(@TypesafeConfig("test.nested") NestedPojo testNestedPojo) { + public void setTestNestedPojo(@TypesafeConfig("method.nested") NestedPojo testNestedPojo) { this.testNestedPojo = testNestedPojo; } @Inject - public void setTestBoolean(@TypesafeConfig("test.yesBoolean") boolean testBoolean) { + public void setTestBoolean(@TypesafeConfig("method.yesBoolean") boolean testBoolean) { this.testBoolean = testBoolean; } diff --git a/src/test/resources/conf/test.conf b/src/test/resources/conf/test.conf index 7cabebc..00b52db 100644 --- a/src/test/resources/conf/test.conf +++ b/src/test/resources/conf/test.conf @@ -50,4 +50,9 @@ test.list.nested = [ nestDouble = 6 nestString = "seven" } -] \ No newline at end of file +] + +provided = ${test} +constructor = ${test} +field = ${test} +method = ${test} \ No newline at end of file From 161d6759beb5389e1050e62b9af4bc43ee7677cb Mon Sep 17 00:00:00 2001 From: Artyom Kozhemyakin Date: Sun, 8 Nov 2015 19:25:30 +0300 Subject: [PATCH 2/3] Fix handling methods with annotated parameters --- src/main/java/com/github/racc/tscg/TypesafeConfigModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/github/racc/tscg/TypesafeConfigModule.java b/src/main/java/com/github/racc/tscg/TypesafeConfigModule.java index f3b7085..5c67d41 100644 --- a/src/main/java/com/github/racc/tscg/TypesafeConfigModule.java +++ b/src/main/java/com/github/racc/tscg/TypesafeConfigModule.java @@ -79,7 +79,7 @@ protected void configure() { bindParameters(params); } - Set annotatedMethods = reflections.getMethodsAnnotatedWith(TypesafeConfig.class); + Set annotatedMethods = reflections.getMethodsWithAnyParamAnnotated(TypesafeConfig.class); for (Method m : annotatedMethods) { Parameter[] params = m.getParameters(); bindParameters(params); From 074cba8742efee38d8acc1ac0ff14f3288bcf16e Mon Sep 17 00:00:00 2001 From: Artyom Kozhemyakin Date: Sun, 8 Nov 2015 19:52:37 +0300 Subject: [PATCH 3/3] Add blank line to the end of the test configuration file --- src/test/resources/conf/test.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/conf/test.conf b/src/test/resources/conf/test.conf index 00b52db..a86cd17 100644 --- a/src/test/resources/conf/test.conf +++ b/src/test/resources/conf/test.conf @@ -55,4 +55,4 @@ test.list.nested = [ provided = ${test} constructor = ${test} field = ${test} -method = ${test} \ No newline at end of file +method = ${test}