Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to find files in the java default package #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down