From 03a24abfc4e79c5205e06ebea17c12d64f3d2c6c Mon Sep 17 00:00:00 2001 From: David Date: Sun, 17 Jan 2016 22:15:25 +0100 Subject: [PATCH] Added support to find files in the java default package as previously the path would consist of "OUTPUT//File.java" leading to no results --- .../google/testing/compile/JavaSourcesSubject.java | 7 +++++-- .../compile/JavaSourcesSubjectFactoryTest.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/testing/compile/JavaSourcesSubject.java b/src/main/java/com/google/testing/compile/JavaSourcesSubject.java index 0ddd83e7..85b0ae6f 100644 --- a/src/main/java/com/google/testing/compile/JavaSourcesSubject.java +++ b/src/main/java/com/google/testing/compile/JavaSourcesSubject.java @@ -517,8 +517,11 @@ public SuccessfulFileClause generatesFileNamed( // packageName is a valid package name. // We're relying on the implementation of location.getName() to be equivalent to the path of // the location. - String expectedFilename = new StringBuilder(location.getName()).append('/') - .append(packageName.replace('.', '/')).append('/').append(relativeName).toString(); + StringBuilder fileNameBuilder = new StringBuilder(location.getName()).append('/'); + if(packageName != null && !packageName.isEmpty()) { + fileNameBuilder.append(packageName.replace('.', '/')).append('/'); + } + String expectedFilename = fileNameBuilder.append(relativeName).toString(); for (JavaFileObject generated : result.generatedFilesByKind().values()) { if (generated.toUri().getPath().endsWith(expectedFilename)) { diff --git a/src/test/java/com/google/testing/compile/JavaSourcesSubjectFactoryTest.java b/src/test/java/com/google/testing/compile/JavaSourcesSubjectFactoryTest.java index f6a010a9..2c071b6e 100644 --- a/src/test/java/com/google/testing/compile/JavaSourcesSubjectFactoryTest.java +++ b/src/test/java/com/google/testing/compile/JavaSourcesSubjectFactoryTest.java @@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.testing.compile.JavaSourceSubjectFactory.javaSource; import static javax.tools.StandardLocation.CLASS_OUTPUT; +import static javax.tools.StandardLocation.SOURCE_OUTPUT; import static org.junit.Assert.fail; import com.google.common.collect.ImmutableList; @@ -386,6 +387,19 @@ public void generatesSources_failWithNoCandidates() { } } + + @Test + public void generatesClassNamed() { + assertAbout(javaSource()) + .that(JavaFileObjects.forResource("HelloWorld.java")) + .processedWith(new GeneratingProcessor()) + .compilesWithoutError() + .and() + .generatesFileNamed(SOURCE_OUTPUT, "", "Blah.java") + .and() + .generatesFileNamed(CLASS_OUTPUT, "", "Blah.class"); + } + @Test public void generatesFileNamed() { assertAbout(javaSource())