assertThat(compilation) .generatedSourceFile("test/TestActivity__NavigationModelBinder") .hasSourceEquivalentTo(binderSource1); assertThat(compilation) .generatedSourceFile("test/TestSuperActivity__NavigationModelBinder") .hasSourceEquivalentTo(binderSource2);
@Test public void writeZoneIds() throws Exception { JavaFileObject source = generatedSource("2010a", "Europe/Berlin", "UTC", "US/Pacific"); JavaFileObject expected = JavaFileObjects.forSourceString(SOURCE_NAME, "" + "package com.gabrielittner.threetenbp;" + "\n" + "import java.lang.String;" + "import java.util.Arrays;" + "import java.util.List;" + "\n" + "final class LazyZoneRules {\n" + " static final String VERSION = \"2010a\";\n" + "\n" + " static final List<String> REGION_IDS = Arrays.asList(\n" + " \"Europe/Berlin\",\n" + " \"UTC\",\n" + " \"US/Pacific\");\n" + " }"); Compilation compilation = javac().compile(source); assertThat(compilation).succeeded(); assertThat(source).hasSourceEquivalentTo(expected); } }
/** * Returns a {@link StringSubject} that makes assertions about the contents of the actual file as * a string. */ public StringSubject contentsAsString(Charset charset) { try { return check() .that(JavaFileObjects.asByteSource(actual()).asCharSource(charset).read()) .named("the contents of " + actualAsString()); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public JavaFileObjectSubject createSubject(FailureMetadata failureMetadata, JavaFileObject that) { return new JavaFileObjectSubject(failureMetadata, that); } }
@Override protected String actualCustomStringRepresentation() { return actual().toUri().getPath(); }
/** * Returns a {@link StringSubject} that makes assertions about the contents of the actual file as * a string. */ public StringSubject contentsAsString(Charset charset) { try { return check() .that(JavaFileObjects.asByteSource(actual()).asCharSource(charset).read()) .named("the contents of " + actualAsString()); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public JavaFileObjectSubject createSubject(FailureMetadata failureMetadata, JavaFileObject that) { return new JavaFileObjectSubject(failureMetadata, that); } }
@Override protected String actualCustomStringRepresentation() { return actual().toUri().getPath(); }
assertThat(compilation) .generatedSourceFile(extraBinderQualifiedName) .hasSourceEquivalentTo(binderSource);
/** * If {@code other} is a {@link JavaFileObject}, tests that their contents are equal. Otherwise * uses {@link Object#equals(Object)}. */ @Override public void isEqualTo(@Nullable Object other) { if (!(other instanceof JavaFileObject)) { super.isEqualTo(other); } JavaFileObject otherFile = (JavaFileObject) other; try { if (!asByteSource(actual()).contentEquals(asByteSource(otherFile))) { fail("is equal to", other); } } catch (IOException e) { throw new RuntimeException(e); } }
assertThat(compilation) .generatedSourceFile(extraBinderQualifiedName) .hasSourceEquivalentTo(expectedSource);
/** * If {@code other} is a {@link JavaFileObject}, tests that their contents are equal. Otherwise * uses {@link Object#equals(Object)}. */ @Override public void isEqualTo(@Nullable Object other) { if (!(other instanceof JavaFileObject)) { super.isEqualTo(other); } JavaFileObject otherFile = (JavaFileObject) other; try { if (!asByteSource(actual()).contentEquals(asByteSource(otherFile))) { fail("is equal to", other); } } catch (IOException e) { throw new RuntimeException(e); } }
assertThat(compilation) .generatedSourceFile("test/TestActivity__NavigationModelBinder") .hasSourceEquivalentTo(binderSource1);
String expectedTitle, BiFunction<ParseResult, ParseResult, TreeDifference> differencingFunction) { ParseResult actualResult = Parser.parse(ImmutableList.of(actual())); CompilationUnitTree actualTree = getOnlyElement(actualResult.compilationUnits()); new TreeContext(actualTree, actualResult.trees())); try { fail( Joiner.on('\n') .join( "==============", "", actual().getCharContent(false))); } catch (IOException e) { throw new IllegalStateException(
assertThat(compilation) .generatedSourceFile(extraBinderQualifiedName) .hasSourceEquivalentTo(expectedSource);
String expectedTitle, BiFunction<ParseResult, ParseResult, TreeDifference> differencingFunction) { ParseResult actualResult = Parser.parse(ImmutableList.of(actual())); CompilationUnitTree actualTree = getOnlyElement(actualResult.compilationUnits()); new TreeContext(actualTree, actualResult.trees())); try { fail( Joiner.on('\n') .join( "==============", "", actual().getCharContent(false))); } catch (IOException e) { throw new IllegalStateException(
assertThat(compilation) .generatedSourceFile("test/TestActivity__NavigationModelBinder") .hasSourceEquivalentTo(binderSource1);
assertThat(compilation) .generatedSourceFile("test/TestActivity__NavigationModelBinder") .hasSourceEquivalentTo(binderSource1);