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())