Skip to content

Commit f0865bb

Browse files
committed
Add a test with both native and support Fragment Intent
1 parent 65d8c36 commit f0865bb

2 files changed

Lines changed: 22 additions & 10 deletions

File tree

AndroidAnnotations/androidannotations/src/test/java/org/androidannotations/generation/ActivityIntentFragmentTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
public class ActivityIntentFragmentTest extends AAProcessorTestHelper {
1111

1212
// Couldn't find better than this for now
13-
private static final String INTENT_FRAGMENT_SIGNATURE = "public static ActivityInManifest_.IntentBuilder_ intent(Fragment fragment)";
14-
private static final String INTENT_FRAGMENT_SUPPORT_SIGNATURE = "public static ActivityInManifest_.IntentBuilder_ intent(Fragment supportFragment)";
13+
private static final String INTENT_FRAGMENT_SIGNATURE = ".*public static ActivityInManifest_\\.IntentBuilder_ intent\\((android\\.app\\.)?Fragment fragment\\).*";
14+
private static final String INTENT_FRAGMENT_SUPPORT_SIGNATURE = ".*public static ActivityInManifest_\\.IntentBuilder_ intent\\((android\\.support\\.v4\\.app\\.)?Fragment supportFragment\\).*";
1515

1616
@Before
1717
public void setup() {
@@ -25,7 +25,7 @@ public void activity_intentFragment_minSdkFroyo_compileWithFroyo() {
2525
File generatedFile = toGeneratedFile(ActivityInManifest.class);
2626

2727
assertCompilationSuccessful(result);
28-
assertGeneratedClassDoesntContains(generatedFile, INTENT_FRAGMENT_SIGNATURE);
28+
assertGeneratedClassDoesntMatches(generatedFile, INTENT_FRAGMENT_SIGNATURE);
2929
}
3030

3131
@Test
@@ -36,7 +36,7 @@ public void activity_intentFragment_minSdkFroyo_compileWithJB() {
3636
File generatedFile = toGeneratedFile(ActivityInManifest.class);
3737

3838
assertCompilationSuccessful(result);
39-
assertGeneratedClassDoesntContains(generatedFile, INTENT_FRAGMENT_SIGNATURE);
39+
assertGeneratedClassDoesntMatches(generatedFile, INTENT_FRAGMENT_SIGNATURE);
4040
}
4141

4242
@Test
@@ -47,7 +47,7 @@ public void activity_intentFragment_minSdkJB_compileWithJB() {
4747
File generatedFile = toGeneratedFile(ActivityInManifest.class);
4848

4949
assertCompilationSuccessful(result);
50-
assertGeneratedClassContains(generatedFile, INTENT_FRAGMENT_SIGNATURE);
50+
assertGeneratedClassMatches(generatedFile, INTENT_FRAGMENT_SIGNATURE);
5151
}
5252

5353
@Test
@@ -59,7 +59,19 @@ public void activity_intentFragment_compileWithSupport() {
5959
File generatedFile = toGeneratedFile(ActivityInManifest.class);
6060

6161
assertCompilationSuccessful(result);
62-
assertGeneratedClassContains(generatedFile, INTENT_FRAGMENT_SUPPORT_SIGNATURE);
62+
assertGeneratedClassMatches(generatedFile, INTENT_FRAGMENT_SUPPORT_SIGNATURE);
63+
}
64+
65+
@Test
66+
public void activity_intentFragment_minSdkJB_compileWithJBAndSupport() {
67+
// To simulate compilation with SDK > 11, we add Fragment in classpath
68+
addManifestProcessorParameter(ActivityIntentFragmentTest.class, "AndroidManifestMinJB.xml");
69+
CompileResult result = compileFiles(toPath(ActivityIntentFragmentTest.class, "Fragment.java"), toPath(ActivityIntentFragmentTest.class, "support/Fragment.java"), ActivityInManifest.class);
70+
File generatedFile = toGeneratedFile(ActivityInManifest.class);
71+
72+
assertCompilationSuccessful(result);
73+
assertGeneratedClassMatches(generatedFile, INTENT_FRAGMENT_SIGNATURE);
74+
assertGeneratedClassMatches(generatedFile, INTENT_FRAGMENT_SUPPORT_SIGNATURE);
6375
}
6476

6577
}

AndroidAnnotations/androidannotations/src/test/java/org/androidannotations/utils/ProcessorTestHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ public CompileResult(List<Diagnostic<? extends JavaFileObject>> diagnostics) {
5858
protected static final String SOURCE_FILE_SUFFIX = ".java";
5959
protected static final String OUTPUT_DIRECTORY = "target/generated-test";
6060

61-
public static void assertGeneratedClassContains(File output, String value) {
61+
public static void assertGeneratedClassMatches(File output, String value) {
6262
String[] outputContent = getContents(output);
6363
for (String line : outputContent) {
64-
if (line.contains(value)) {
64+
if (line.matches(value)) {
6565
return;
6666
}
6767
}
6868
fail("Expected value \"" + value + "\" couldn't be found in file " + output.getAbsolutePath());
6969
}
7070

71-
public static void assertGeneratedClassDoesntContains(File output, String value) {
71+
public static void assertGeneratedClassDoesntMatches(File output, String value) {
7272
String[] outputContent = getContents(output);
7373
for (String line : outputContent) {
74-
if (line.contains(value)) {
74+
if (line.matches(value)) {
7575
fail("Value \"" + value + "\" shouldn't be in file " + output.getAbsolutePath());
7676
}
7777
}

0 commit comments

Comments
 (0)