-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add inner class support * add test for InnerClass support * fix qualifiedBuilderName generation and add test for inner class with protected fields * add expected output source to InnerClassTest
- Loading branch information
1 parent
c395c80
commit 36997f1
Showing
8 changed files
with
196 additions
and
8 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
19 changes: 19 additions & 0 deletions
19
processor/src/test/java/com/hannesdorfmann/fragmentargs/processor/CompileTest.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,19 @@ | ||
package com.hannesdorfmann.fragmentargs.processor; | ||
|
||
import com.google.testing.compile.JavaFileObjects; | ||
|
||
import static com.google.common.truth.Truth.assert_; | ||
import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource; | ||
|
||
public final class CompileTest { | ||
|
||
public static void assertClassCompilesWithoutError(final String classResourceName, final String outputClassResourceName) { | ||
assert_().about(javaSource()) | ||
.that(JavaFileObjects.forResource(classResourceName)) | ||
.processedWith(new ArgProcessor()) | ||
.compilesWithoutError() | ||
.and() | ||
.generatesSources(JavaFileObjects.forResource(outputClassResourceName)); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
processor/src/test/java/com/hannesdorfmann/fragmentargs/processor/InnerClassTest.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,18 @@ | ||
package com.hannesdorfmann.fragmentargs.processor; | ||
|
||
import org.junit.Test; | ||
|
||
import static com.hannesdorfmann.fragmentargs.processor.CompileTest.assertClassCompilesWithoutError; | ||
|
||
public class InnerClassTest { | ||
|
||
@Test | ||
public void innerClass() { | ||
assertClassCompilesWithoutError("ClassWithInnerClass.java", "ClassWithInnerClassBuilder.java"); | ||
} | ||
|
||
@Test | ||
public void innerClassWithProtectedField() { | ||
assertClassCompilesWithoutError("InnerClassWithProtectedField.java", "InnerClassWithProtectedFieldBuilder.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,16 @@ | ||
package com.hannesdorfmann.fragmentargs.processor.test; | ||
|
||
@com.hannesdorfmann.fragmentargs.annotation.FragmentWithArgs | ||
public class ClassWithInnerClass extends android.app.Fragment { | ||
|
||
@com.hannesdorfmann.fragmentargs.annotation.Arg | ||
String arg; | ||
|
||
@com.hannesdorfmann.fragmentargs.annotation.FragmentWithArgs | ||
public static class InnerClass extends android.app.Fragment { | ||
|
||
@com.hannesdorfmann.fragmentargs.annotation.Arg | ||
String arg; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
processor/src/test/resources/ClassWithInnerClassBuilder.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,39 @@ | ||
package com.hannesdorfmann.fragmentargs.processor.test; | ||
|
||
import android.os.Bundle; | ||
|
||
public final class ClassWithInnerClassBuilder { | ||
|
||
private final Bundle mArguments = new Bundle(); | ||
|
||
public ClassWithInnerClassBuilder(String arg) { | ||
|
||
mArguments.putString("arg", arg); | ||
} | ||
|
||
public static ClassWithInnerClass newClassWithInnerClass(String arg) { | ||
return new ClassWithInnerClassBuilder(arg).build(); | ||
} | ||
|
||
public Bundle buildBundle() { | ||
return new Bundle(mArguments); | ||
} | ||
|
||
public static final void injectArguments(ClassWithInnerClass fragment) { | ||
Bundle args = fragment.getArguments(); | ||
if (args == null) { | ||
throw new IllegalStateException("No arguments set. Have you set up this Fragment with the corresponding FragmentArgs Builder? "); | ||
} | ||
|
||
if (!args.containsKey("arg")) { | ||
throw new IllegalStateException("required argument arg is not set"); | ||
} | ||
fragment.arg = args.getString("arg"); | ||
} | ||
|
||
public ClassWithInnerClass build() { | ||
ClassWithInnerClass fragment = new ClassWithInnerClass(); | ||
fragment.setArguments(mArguments); | ||
return fragment; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
processor/src/test/resources/InnerClassWithProtectedField.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,16 @@ | ||
package com.hannesdorfmann.fragmentargs.processor.test; | ||
|
||
@com.hannesdorfmann.fragmentargs.annotation.FragmentWithArgs | ||
public class InnerClassWithProtectedField extends android.app.Fragment { | ||
|
||
@com.hannesdorfmann.fragmentargs.annotation.Arg | ||
protected String arg; | ||
|
||
@com.hannesdorfmann.fragmentargs.annotation.FragmentWithArgs | ||
public static class InnerClass extends android.app.Fragment { | ||
|
||
@com.hannesdorfmann.fragmentargs.annotation.Arg | ||
protected String arg; | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
processor/src/test/resources/InnerClassWithProtectedFieldBuilder.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,39 @@ | ||
package com.hannesdorfmann.fragmentargs.processor.test; | ||
|
||
import android.os.Bundle; | ||
|
||
public final class InnerClassWithProtectedFieldBuilder { | ||
|
||
private final Bundle mArguments = new Bundle(); | ||
|
||
public InnerClassWithProtectedFieldBuilder(String arg) { | ||
|
||
mArguments.putString("arg", arg); | ||
} | ||
|
||
public static InnerClassWithProtectedField newInnerClassWithProtectedField(String arg) { | ||
return new InnerClassWithProtectedFieldBuilder(arg).build(); | ||
} | ||
|
||
public Bundle buildBundle() { | ||
return new Bundle(mArguments); | ||
} | ||
|
||
public static final void injectArguments(InnerClassWithProtectedField fragment) { | ||
Bundle args = fragment.getArguments(); | ||
if (args == null) { | ||
throw new IllegalStateException("No arguments set. Have you set up this Fragment with the corresponding FragmentArgs Builder? "); | ||
} | ||
|
||
if (!args.containsKey("arg")) { | ||
throw new IllegalStateException("required argument arg is not set"); | ||
} | ||
fragment.arg = args.getString("arg"); | ||
} | ||
|
||
public InnerClassWithProtectedField build() { | ||
InnerClassWithProtectedField fragment = new InnerClassWithProtectedField(); | ||
fragment.setArguments(mArguments); | ||
return fragment; | ||
} | ||
} |