Skip to content

Commit

Permalink
update InnerClassTest to test the generated InnerClassBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasBoehm committed Jul 4, 2018
1 parent 935e872 commit 1319aba
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
public class GenericsTest {

@Test
public void protectedField() {
public void classWithGenerics() {
assertClassCompilesWithoutError("ClassWithGenerics.java", "ClassWithGenericsBuilder.java");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class InnerClassTest {

@Test
public void innerClass() {
assertClassCompilesWithoutError("ClassWithInnerClass.java", "ClassWithInnerClassBuilder.java");
assertClassCompilesWithoutError("ClassWithInnerClass.java", "ClassWithInnerClass$$InnerClassBuilder.java");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
package com.hannesdorfmann.fragmentargs.processor;

import com.google.testing.compile.JavaFileObjects;

import org.junit.Test;

import static com.google.common.truth.Truth.assert_;
import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource;
import static com.hannesdorfmann.fragmentargs.processor.CompileTest.assertClassCompilesWithoutError;

public class ProtectedAccessTest {
@Test
public void protectedField() {
assert_().about(javaSource())
.that(JavaFileObjects.forResource("ClassWithProtectedField.java"))
.processedWith(new ArgProcessor())
.compilesWithoutError()
.and()
.generatesSources(JavaFileObjects.forResource("ClassWithProtectedFieldBuilder.java"));
assertClassCompilesWithoutError("ClassWithProtectedField.java", "ClassWithProtectedFieldBuilder.java");
}

@Test
public void protectedSetter() {
assert_().about(javaSource())
.that(JavaFileObjects.forResource("ClassWithProtectedSetter.java"))
.processedWith(new ArgProcessor())
.compilesWithoutError()
.and()
.generatesSources(JavaFileObjects.forResource("ClassWithProtectedSetterBuilder.java"));
assertClassCompilesWithoutError("ClassWithProtectedSetter.java", "ClassWithProtectedSetterBuilder.java");
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package com.hannesdorfmann.fragmentargs.processor.test;

import android.os.Bundle;
import com.hannesdorfmann.fragmentargs.processor.test.ClassWithInnerClass.InnerClass;

public final class ClassWithInnerClassBuilder {
public final class ClassWithInnerClass$$InnerClassBuilder {

private final Bundle mArguments = new Bundle();

public ClassWithInnerClassBuilder(String arg) {
public ClassWithInnerClass$$InnerClassBuilder(String arg) {

mArguments.putString("arg", arg);
}

public static ClassWithInnerClass newClassWithInnerClass(String arg) {
return new ClassWithInnerClassBuilder(arg).build();
public static InnerClass newInnerClass(String arg) {
return new ClassWithInnerClass$$InnerClassBuilder(arg).build();
}

public Bundle buildBundle() {
return new Bundle(mArguments);
}

public static final void injectArguments(ClassWithInnerClass fragment) {
public static final void injectArguments(InnerClass 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? ");
Expand All @@ -31,8 +32,8 @@ public static final void injectArguments(ClassWithInnerClass fragment) {
fragment.arg = args.getString("arg");
}

public ClassWithInnerClass build() {
ClassWithInnerClass fragment = new ClassWithInnerClass();
public InnerClass build() {
InnerClass fragment = new InnerClass();
fragment.setArguments(mArguments);
return fragment;
}
Expand Down
4 changes: 0 additions & 4 deletions processor/src/test/resources/ClassWithInnerClass.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
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 {

Expand Down

0 comments on commit 1319aba

Please sign in to comment.