/** * Asserts that compilation generated a file named {@code fileName} in package {@code * packageName}. */ @CanIgnoreReturnValue public JavaFileObjectSubject generatedFile( Location location, String packageName, String fileName) { return checkGeneratedFile( actual().generatedFile(location, packageName, fileName), location, "named \"%s\" in %s", fileName, packageName.isEmpty() ? "the default package" : String.format("package \"%s\"", packageName)); }
/** * Asserts that compilation generated a file named {@code fileName} in package {@code * packageName}. */ @CanIgnoreReturnValue public JavaFileObjectSubject generatedFile( Location location, String packageName, String fileName) { return checkGeneratedFile( actual().generatedFile(location, packageName, fileName), location, "named \"%s\" in %s", fileName, packageName.isEmpty() ? "the default package" : String.format("package \"%s\"", packageName)); }
/** * Returns the diagnostics that match one of the kinds and a pattern. If none match, fails the * test. */ private ImmutableList<Diagnostic<? extends JavaFileObject>> findMatchingDiagnostics( String expectedDiagnostic, Pattern expectedPattern, Diagnostic.Kind kind, Diagnostic.Kind... more) { ImmutableList<Diagnostic<? extends JavaFileObject>> diagnosticsOfKind = actual().diagnosticsOfKind(kind, more); ImmutableList<Diagnostic<? extends JavaFileObject>> diagnosticsWithMessage = diagnosticsOfKind .stream() .filter(diagnostic -> expectedPattern.matcher(diagnostic.getMessage(null)).find()) .collect(toImmutableList()); if (diagnosticsWithMessage.isEmpty()) { failWithRawMessage( messageListing(diagnosticsOfKind, "Expected %s, but only found:", expectedDiagnostic)); } return diagnosticsWithMessage; }
private JavaFileObjectSubject checkGeneratedFile( Optional<JavaFileObject> generatedFile, Location location, String format, Object... args) { if (!generatedFile.isPresent()) { StringBuilder builder = new StringBuilder("generated the file "); builder.append(args.length == 0 ? format : String.format(format, args)); builder.append("; it generated:\n"); for (JavaFileObject generated : actual().generatedFiles()) { if (generated.toUri().getPath().contains(location.getName())) { builder.append(" ").append(generated.toUri().getPath()).append('\n'); } } fail(builder.toString()); return ignoreCheck().about(javaFileObjects()).that(ALREADY_FAILED); } return check().about(javaFileObjects()).that(generatedFile.get()); }
/** Asserts that compilation generated a file at {@code path}. */ @CanIgnoreReturnValue public JavaFileObjectSubject generatedFile(Location location, String path) { return checkGeneratedFile(actual().generatedFile(location, path), location, path); }
/** Asserts that compilation generated a file at {@code path}. */ @CanIgnoreReturnValue public JavaFileObjectSubject generatedFile(Location location, String path) { return checkGeneratedFile(actual().generatedFile(location, path), location, path); }
private JavaFileObjectSubject checkGeneratedFile( Optional<JavaFileObject> generatedFile, Location location, String format, Object... args) { if (!generatedFile.isPresent()) { StringBuilder builder = new StringBuilder("generated the file "); builder.append(args.length == 0 ? format : String.format(format, args)); builder.append("; it generated:\n"); for (JavaFileObject generated : actual().generatedFiles()) { if (generated.toUri().getPath().contains(location.getName())) { builder.append(" ").append(generated.toUri().getPath()).append('\n'); } } fail(builder.toString()); return ignoreCheck().about(javaFileObjects()).that(ALREADY_FAILED); } return check().about(javaFileObjects()).that(generatedFile.get()); }
/** * Returns the diagnostics that match one of the kinds and a pattern. If none match, fails the * test. */ private ImmutableList<Diagnostic<? extends JavaFileObject>> findMatchingDiagnostics( String expectedDiagnostic, Pattern expectedPattern, Diagnostic.Kind kind, Diagnostic.Kind... more) { ImmutableList<Diagnostic<? extends JavaFileObject>> diagnosticsOfKind = actual().diagnosticsOfKind(kind, more); ImmutableList<Diagnostic<? extends JavaFileObject>> diagnosticsWithMessage = diagnosticsOfKind .stream() .filter(diagnostic -> expectedPattern.matcher(diagnostic.getMessage(null)).find()) .collect(toImmutableList()); if (diagnosticsWithMessage.isEmpty()) { failWithoutActual( simpleFact( messageListing( diagnosticsOfKind, "Expected %s, but only found:", expectedDiagnostic))); } return diagnosticsWithMessage; }
private void checkDiagnosticCount( int expectedCount, Diagnostic.Kind kind, Diagnostic.Kind... more) { Iterable<Diagnostic<? extends JavaFileObject>> diagnostics = actual().diagnosticsOfKind(kind, more); int actualCount = size(diagnostics); if (actualCount != expectedCount) { failWithRawMessage( messageListing( diagnostics, "Expected %d %s, but found the following %d %s:", expectedCount, kindPlural(kind), actualCount, kindPlural(kind))); } }
private void checkDiagnosticCount( int expectedCount, Diagnostic.Kind kind, Diagnostic.Kind... more) { Iterable<Diagnostic<? extends JavaFileObject>> diagnostics = actual().diagnosticsOfKind(kind, more); int actualCount = size(diagnostics); if (actualCount != expectedCount) { failWithoutActual( simpleFact( messageListing( diagnostics, "Expected %d %s, but found the following %d %s:", expectedCount, kindPlural(kind), actualCount, kindPlural(kind)))); } }