com.google.common.truth.Truth Java Examples

The following examples show how to use com.google.common.truth.Truth. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassPathBuilderTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolve_artifactProblems() {
  // In the full dependency tree of hibernate-core, xerces-impl:2.6.2 and xml-apis:2.6.2 are not
  // available in Maven Central.
  Artifact hibernateCore = new DefaultArtifact("org.hibernate:hibernate-core:jar:3.5.1-Final");
  ClassPathResult result = classPathBuilder.resolve(ImmutableList.of(hibernateCore));

  ImmutableList<UnresolvableArtifactProblem> artifactProblems = result.getArtifactProblems();

  List<String> coordinates = artifactProblems.stream()
          .map(x -> x.getArtifact())
          .map(x -> x.toString())
          .collect(Collectors.toList());

  Truth.assertThat(coordinates).containsExactly("xerces:xerces-impl:jar:2.6.2",
      "xml-apis:xml-apis:jar:2.6.2");
}
 
Example #2
Source File: SymbolReferencesTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddAll() throws IOException {
  SymbolReferences.Builder builder1 = new SymbolReferences.Builder();
  SymbolReferences.Builder builder2 = new SymbolReferences.Builder();

  builder1.addClassReference(sourceClass, classSymbol);
  builder1.addMethodReference(sourceClass, methodSymbol);
  builder1.addFieldReference(sourceClass, fieldSymbol);

  ClassFile sourceClass2 = new ClassFile(new ClassPathEntry(path), "com.google.Bar");
  builder2.addClassReference(sourceClass2, classSymbol);
  builder2.addMethodReference(sourceClass2, methodSymbol);
  builder2.addFieldReference(sourceClass2, fieldSymbol);

  builder1.addAll(builder2);
  SymbolReferences references = builder1.build();

  Truth.assertThat(references.getClassSymbols(sourceClass)).contains(classSymbol);
  Truth.assertThat(references.getMethodSymbols(sourceClass)).contains(methodSymbol);
  Truth.assertThat(references.getFieldSymbols(sourceClass)).contains(fieldSymbol);
  Truth.assertThat(references.getClassSymbols(sourceClass2)).contains(classSymbol);
  Truth.assertThat(references.getMethodSymbols(sourceClass2)).contains(methodSymbol);
  Truth.assertThat(references.getFieldSymbols(sourceClass2)).contains(fieldSymbol);
}
 
Example #3
Source File: SafeMethodCachingInterceptorTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void cacheHit_doesNotResetExpiration() throws Exception {
  cacheControlDirectives.add("max-age=1");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  sleepAtLeast(1001);

  HelloReply reply3 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  assertSame(reply1, reply2);
  assertNotEquals(reply1, reply3);
  Truth.assertThat(cache.internalCache).hasSize(1);
  Truth.assertThat(cache.removedKeys).hasSize(1);
}
 
Example #4
Source File: ClassPathEntryTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetClassNames_innerClasses()
    throws IOException, ArtifactResolutionException, URISyntaxException {

  ClassPathEntry entry = TestHelper.classPathEntryOfResource(
      "testdata/conscrypt-openjdk-uber-1.4.2.jar");
  ImmutableSet<String> classFileNames = entry.getFileNames();
  Truth.assertThat(classFileNames).containsAtLeast(
      "org.conscrypt.OpenSSLSignature$1",
      "org.conscrypt.OpenSSLContextImpl$TLSv1",
      "org.conscrypt.TrustManagerImpl$1",
      "org.conscrypt.PeerInfoProvider",
      "org.conscrypt.PeerInfoProvider$1",
      "org.conscrypt.ExternalSession$Provider",
      "org.conscrypt.OpenSSLMac");
}
 
Example #5
Source File: PhotosContainerResourceTest.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyTransmogrifyAlbums_oddDivision() throws Exception {
  TransmogrificationConfig config = new TransmogrificationConfig() {
      public int getAlbumMaxSize() { return 2;}
  };
  List<PhotoAlbum> albums =
      ImmutableList.of(new PhotoAlbum("id1", "albumb1", "This is a fake album"));

  List<PhotoModel> photos =
      ImmutableList.of(
          new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1",
              false),
          new PhotoModel("Pic3", "http://fake.com/2.jpg", "A pic", "image/jpg", "p3", "id1",
              false),
          new PhotoModel(
              "Pic2", "https://fake.com/pic.png", "fine art", "image/png", "p2", "id1", false));

  PhotosContainerResource data = new PhotosContainerResource(albums, photos);
  data.transmogrify(config);
  Truth.assertThat(data.getAlbums()).hasSize(2);
  Truth.assertThat(data.getPhotos()).hasSize(3);
}
 
Example #6
Source File: ExclusionFilesTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testParse_targetPackage_subpackage()
    throws URISyntaxException, IOException, SAXException, VerifierConfigurationException {
  Path exclusionFile = absolutePathOfResource("exclusion-sample-rules/target-package.xml");

  ImmutableList<LinkageErrorMatcher> matchers = ExclusionFiles.parse(exclusionFile);
  Truth.assertThat(matchers).hasSize(1);
  LinkageErrorMatcher matcher = matchers.get(0);

  // Package "com.google" should match "com.google.cloud.Foo"
  SymbolProblem symbolProblemToMatch =
      new SymbolProblem(
          new MethodSymbol("com.google.cloud.Foo", "methodA", "()Ljava.lang.String;", false),
          ErrorType.INACCESSIBLE_MEMBER,
          new ClassFile(new ClassPathEntry(Paths.get("dummy.jar")), "com.cloud.google.Foo"));
  boolean result =
      matcher.match(
          symbolProblemToMatch,
          new ClassFile(
              new ClassPathEntry(Paths.get("dummy.jar")), "reactor.core.publisher.Traces"));
  assertTrue(result);
}
 
Example #7
Source File: SafeMethodCachingInterceptorTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Test
public void separateResponseCacheControlDirectives_parsesWithoutError() throws Exception {
  cacheControlDirectives.add("max-age=1");
  cacheControlDirectives.add("no-store , no-cache");

  HelloReply reply1 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);
  HelloReply reply2 =
      ClientCalls.blockingUnaryCall(
          channelToUse, safeGreeterSayHelloMethod, CallOptions.DEFAULT, message);

  assertNotEquals(reply1, reply2);
  Truth.assertThat(cache.internalCache).isEmpty();
  Truth.assertThat(cache.removedKeys).isEmpty();
}
 
Example #8
Source File: ExclusionFilesTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testParse_sourceAndTarget_unmatch()
    throws URISyntaxException, IOException, SAXException, VerifierConfigurationException {
  Path exclusionFile = absolutePathOfResource("exclusion-sample-rules/source-and-target.xml");

  ImmutableList<LinkageErrorMatcher> matchers = ExclusionFiles.parse(exclusionFile);
  Truth.assertThat(matchers).hasSize(1);
  LinkageErrorMatcher matcher = matchers.get(0);

  SymbolProblem symbolProblemToMatch =
      new SymbolProblem(
          new MethodSymbol("com.google.Foo", "methodA", "()Ljava.lang.String;", false),
          ErrorType.INACCESSIBLE_MEMBER,
          new ClassFile(new ClassPathEntry(Paths.get("dummy.jar")), "com.google.Foo"));
  boolean result =
      matcher.match(
          symbolProblemToMatch,
          new ClassFile(
              new ClassPathEntry(Paths.get("dummy.jar")), "com.google.Bar")); // No match
  assertFalse(result);
}
 
Example #9
Source File: ExclusionFilesTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testParse_targetPackage()
    throws URISyntaxException, IOException, SAXException, VerifierConfigurationException {
  Path exclusionFile = absolutePathOfResource("exclusion-sample-rules/target-package.xml");

  ImmutableList<LinkageErrorMatcher> matchers = ExclusionFiles.parse(exclusionFile);
  Truth.assertThat(matchers).hasSize(1);
  LinkageErrorMatcher matcher = matchers.get(0);

  SymbolProblem symbolProblemToMatch =
      new SymbolProblem(
          new MethodSymbol("com.google.Foo", "methodA", "()Ljava.lang.String;", false),
          ErrorType.INACCESSIBLE_MEMBER,
          new ClassFile(new ClassPathEntry(Paths.get("dummy.jar")), "com.google.Foo"));
  boolean result =
      matcher.match(
          symbolProblemToMatch,
          new ClassFile(
              new ClassPathEntry(Paths.get("dummy.jar")), "reactor.core.publisher.Traces"));
  assertTrue(result);
}
 
Example #10
Source File: DependencyGraphBuilderTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildLinkageCheckDependencyGraph_catchRootException() {
  // This should not throw exception
  DependencyGraph result =
      dependencyGraphBuilder.buildFullDependencyGraph(
          ImmutableList.of(new DefaultArtifact("ant:ant:jar:1.6.2")));

  Set<UnresolvableArtifactProblem> problems = result.getUnresolvedArtifacts();

  Truth.assertThat(problems)
      .comparingElementsUsing(problemOnArtifact)
      .containsAtLeast("xerces:xerces-impl:2.6.2", "xml-apis:xml-apis:2.6.2");

  Truth.assertThat(problems).hasSize(2);
  Truth.assertThat(problems)
      .comparingElementsUsing(
          Correspondence.transforming(UnresolvableArtifactProblem::toString, "has description"))
      .containsExactly(
          "xerces:xerces-impl:jar:2.6.2 was not resolved. Dependency path: ant:ant:jar:1.6.2"
              + " (compile) > xerces:xerces-impl:jar:2.6.2 (compile?)",
          "xml-apis:xml-apis:jar:2.6.2 was not resolved. Dependency path: ant:ant:jar:1.6.2"
              + " (compile) > xml-apis:xml-apis:jar:2.6.2 (compile?)");
}
 
Example #11
Source File: LinkageCheckerTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testGenerateInputClasspathFromLinkageCheckOption_recordMissingDependency()
    throws ParseException, RepositoryException, IOException {
  // tomcat-jasper has missing dependency (not optional):
  //   org.apache.tomcat:tomcat-jasper:jar:8.0.9
  //     org.eclipse.jdt.core.compiler:ecj:jar:4.4RC4 (not found in Maven central)
  LinkageCheckerArguments parsedArguments =
      LinkageCheckerArguments.readCommandLine(
          "--artifacts", "org.apache.tomcat:tomcat-jasper:8.0.9");

  ImmutableList<UnresolvableArtifactProblem> artifactProblems =
      classPathBuilder.resolve(parsedArguments.getArtifacts()).getArtifactProblems();
  Truth.assertThat(artifactProblems)
      .comparingElementsUsing(
          Correspondence.transforming(
              (UnresolvableArtifactProblem problem) -> problem.getArtifact().toString(),
              "problem with Maven coordinate"))
      .contains("org.eclipse.jdt.core.compiler:ecj:jar:4.4RC4");
}
 
Example #12
Source File: PhotosContainerResourceTest.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
@Test
  public void verifyTransmogrifyPhotos_TitleNoForbiddenCharacters() throws Exception {
    TransmogrificationConfig config = new TransmogrificationConfig();
    List<PhotoAlbum> albums =
        ImmutableList.of(new PhotoAlbum("id1", "albumb1", "This:a fake album!"));

    List<PhotoModel> photos =
        ImmutableList.of(
            new PhotoModel("Pic?1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1",
                false),
            new PhotoModel("Pic:3", "http://fake.com/2.jpg", "A pic", "image/jpg", "p3", "id1",
                false),
            new PhotoModel(
                "Pic2", "https://fake.com/pic.png", "fine art", "image/png", "p2", null, false));

    PhotosContainerResource data = new PhotosContainerResource(albums, photos);
    data.transmogrify(config);
    Truth.assertThat(Iterables.get(data.getPhotos(),0).getTitle()).isEqualTo("Pic?1");
    Truth.assertThat(Iterables.get(data.getPhotos(),1).getTitle()).isEqualTo("Pic:3");
    Truth.assertThat(Iterables.get(data.getPhotos(),2).getTitle()).isEqualTo("Pic2");
}
 
Example #13
Source File: PhotosContainerResourceTest.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyTransmogrifyAlbums_evenDivision() throws Exception {
  TransmogrificationConfig config = new TransmogrificationConfig() {
      public int getAlbumMaxSize() { return 2;}
  };
  List<PhotoAlbum> albums =
      ImmutableList.of(new PhotoAlbum("id1", "albumb1", "This is a fake album"));

  List<PhotoModel> photos =
      ImmutableList.of(
          new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1",
              false),
          new PhotoModel("Pic3", "http://fake.com/2.jpg", "A pic", "image/jpg", "p3", "id1",
              false),
          new PhotoModel("Pic4", "http://fake.com/3.jpg", "A pic", "image/jpg", "p4", "id1",
              false),
          new PhotoModel(
              "Pic2", "https://fake.com/pic.png", "fine art", "image/png", "p2", "id1", false));

  PhotosContainerResource data = new PhotosContainerResource(albums, photos);
  data.transmogrify(config);
  Truth.assertThat(data.getAlbums()).hasSize(2);
  Truth.assertThat(data.getPhotos()).hasSize(4);
}
 
Example #14
Source File: ClassDumperTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsSystemClass() throws URISyntaxException, IOException {
  ClassDumper classDumper =
      ClassDumper.create(
          ImmutableList.of(classPathEntryOfResource("testdata/guava-23.5-jre.jar")));

  List<String> javaRuntimeClasses =
      ImmutableList.of(
          "java.lang.String",
          "java.lang.Object",
          "[Ljava.lang.String;",
          "java.util.ArrayList",
          "javax.net.SocketFactory"); // from rt.jar
  for (String javaRuntimeClassName : javaRuntimeClasses) {
    Truth.assertThat(classDumper.isSystemClass(javaRuntimeClassName)).isTrue();
  }

  // Even though Guava is passed to the constructor, it should not report ImmutableList as
  // Java runtime class.
  List<String> nonJavaRuntimeClasses =
      ImmutableList.of("com.google.common.collect.ImmutableList", "foo.bar.Baz");
  for (String nonJavaRuntimeClassName : nonJavaRuntimeClasses) {
    Truth.assertThat(classDumper.isSystemClass(nonJavaRuntimeClassName)).isFalse();
  }
}
 
Example #15
Source File: ClassPathBuilderTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveClassPath_validCoordinate() {
  List<ClassPathEntry> entries = resolveClassPath("io.grpc:grpc-auth:1.15.1");

  Truth.assertThat(entries)
      .comparingElementsUsing(TestHelper.COORDINATES)
      .contains("io.grpc:grpc-auth:1.15.1");
  Truth.assertThat(entries)
      .comparingElementsUsing(TestHelper.COORDINATES)
      .contains("com.google.auth:google-auth-library-credentials:0.9.0");
  entries.forEach(
      entry ->
          Truth.assertWithMessage("Every returned path should be an absolute path")
              .that(entry.getJar().isAbsolute())
              .isTrue());
}
 
Example #16
Source File: LinkageCheckerTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindSymbolProblems_nativeMethodsOnAbstractClass() throws IOException {
  ImmutableList<ClassPathEntry> jars = resolvePaths("com.oracle.substratevm:svm:19.2.0.1");

  LinkageChecker linkageChecker = LinkageChecker.create(jars);

  ImmutableSetMultimap<SymbolProblem, ClassFile> symbolProblems =
      linkageChecker.findSymbolProblems();

  // com.oracle.svm.core.genscavenge.PinnedAllocatorImpl extends an abstract class
  // com.oracle.svm.core.heap.PinnedAllocator. The superclass has native methods, such as
  // "newInstance". These native methods should not be reported as unimplemented methods.
  String unexpectedClass = "com.oracle.svm.core.genscavenge.PinnedAllocatorImpl";
  Truth.assertThat(symbolProblems.keySet())
      .comparingElementsUsing(HAS_SYMBOL_IN_CLASS)
      .doesNotContain(unexpectedClass);
}
 
Example #17
Source File: PhotosContainerResourceTest.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyTransmogrifyPhotos_TitleTooLong() throws Exception {
  TransmogrificationConfig config = new TransmogrificationConfig() {
      public int getPhotoTitleMaxLength() {
          return 3;
      }    
  };
  List<PhotoAlbum> albums =
      ImmutableList.of(new PhotoAlbum("id1", "albumb1", "This:a fake album!"));

  List<PhotoModel> photos =
      ImmutableList.of(
          new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1",
              false),
          new PhotoModel("Pic3", "http://fake.com/2.jpg", "A pic", "image/jpg", "p3", "id1",
              false),
          new PhotoModel(
              "P2", "https://fake.com/pic.png", "fine art", "image/png", "p2", null, false));

  PhotosContainerResource data = new PhotosContainerResource(albums, photos);
  data.transmogrify(config);
  Truth.assertThat(Iterables.get(data.getPhotos(),0).getTitle()).hasLength(3);
  Truth.assertThat(Iterables.get(data.getPhotos(),1).getTitle()).hasLength(3);
  Truth.assertThat(Iterables.get(data.getPhotos(),2).getTitle()).isEqualTo("P2");
}
 
Example #18
Source File: LinkageCheckerRuleTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testExecute_shouldFailForBadProject() throws RepositoryException {
  try {
    // This artifact is known to contain classes missing dependencies
    setupMockDependencyResolution("com.google.appengine:appengine-api-1.0-sdk:1.9.64");
    rule.execute(mockRuleHelper);
    Assert.fail(
        "The rule should raise an EnforcerRuleException for artifacts missing dependencies");
  } catch (EnforcerRuleException ex) {
    // pass
    ArgumentCaptor<String> errorMessageCaptor = ArgumentCaptor.forClass(String.class);
    verify(mockLog, times(2)).error(errorMessageCaptor.capture());

    List<String> errorMessages = errorMessageCaptor.getAllValues();
    Truth.assertThat(errorMessages.get(0)).startsWith("Linkage Checker rule found 112 errors.");
    Truth.assertThat(errorMessages.get(1))
        .startsWith(
            "Problematic artifacts in the dependency tree:\n"
                + "com.google.appengine:appengine-api-1.0-sdk:1.9.64 is at:\n"
                + "  a:b:jar:0.1 / com.google.appengine:appengine-api-1.0-sdk:1.9.64 (compile)");
    assertEquals("Failed while checking class path. See above error report.", ex.getMessage());
  }
}
 
Example #19
Source File: LinkageCheckerTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testScannedSymbols() throws IOException {
  List<ClassPathEntry> paths = ImmutableList.of(guavaJar);
  LinkageChecker linkageChecker = LinkageChecker.create(paths);

  SymbolReferences symbolReferences = linkageChecker.getSymbolReferences();
  // These example symbols below are picked up through javap command. For example
  // javap -classpath src/test/resources/testdata/guava-23.5-jre.jar \
  //   -v com/google/common/util/concurrent/Monitor
  Truth.assertThat(symbolReferences.getClassSymbols(
      new ClassFile(guavaJar, "com.google.common.util.concurrent.Service")))
      .contains(
          new ClassSymbol("java.util.concurrent.TimeoutException"));
  ClassFile monitor = new ClassFile(guavaJar, "com.google.common.util.concurrent.Monitor");
  Truth.assertThat(symbolReferences.getMethodSymbols(monitor))
      .contains(
          new MethodSymbol(
              "com.google.common.base.Preconditions",
              "checkNotNull",
              "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
              false));
  Truth.assertThat(symbolReferences.getFieldSymbols(monitor))
      .contains(
          new FieldSymbol("com.google.common.util.concurrent.Monitor$Guard", "waiterCount", "I"));
}
 
Example #20
Source File: LinkageCheckerTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testFindSymbolProblems_shouldSuppressJvmCIPackage() throws IOException {
  // There was a false positive of missing class problem of
  // com.oracle.graal.pointsto.meta.AnalysisType (in com.oracle.substratevm:svm:19.0.0). The class
  // was in the class path but its parent class was missing.
  // https://github.com/GoogleCloudPlatform/cloud-opensource-java/issues/933
  ImmutableList<ClassPathEntry> jars = resolvePaths("com.oracle.substratevm:svm:19.2.0.1");

  LinkageChecker linkageChecker = LinkageChecker.create(jars);

  ImmutableSetMultimap<SymbolProblem, ClassFile> symbolProblems =
      linkageChecker.findSymbolProblems();
  Truth.assertWithMessage("Missing classes from jdk.vm.ci should not be reported")
      .that(symbolProblems.keySet())
      .isEmpty();
}
 
Example #21
Source File: PhotosContainerResourceTest.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyTransmogrifyAlbums_NameNoLengthLimit() throws Exception {
  TransmogrificationConfig config = new TransmogrificationConfig();
  List<PhotoAlbum> albums =
      ImmutableList.of(new PhotoAlbum("id1", "albumb1", "This:a fake album!"));

  List<PhotoModel> photos =
      ImmutableList.of(
          new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1",
              false),
          new PhotoModel("Pic3", "http://fake.com/2.jpg", "A pic", "image/jpg", "p3", "id1",
              false),
          new PhotoModel(
              "Pic2", "https://fake.com/pic.png", "fine art", "image/png", "p2", null, false));

  PhotosContainerResource data = new PhotosContainerResource(albums, photos);
  data.transmogrify(config);
  Truth.assertThat(Iterables.get(data.getAlbums(),0).getName()).hasLength(7);
}
 
Example #22
Source File: PhotosContainerResourceTest.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyTransmogrifyAlbums_NameNoForbiddenCharacters() throws Exception {
  TransmogrificationConfig config = new TransmogrificationConfig();
  List<PhotoAlbum> albums =
      ImmutableList.of(new PhotoAlbum("id1", "This:a fake album!", "This:a fake album!"));

  List<PhotoModel> photos =
      ImmutableList.of(
          new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1",
              false),
          new PhotoModel("Pic3", "http://fake.com/2.jpg", "A pic", "image/jpg", "p3", "id1",
              false),
          new PhotoModel(
              "Pic2", "https://fake.com/pic.png", "fine art", "image/png", "p2", null, false));

  PhotosContainerResource data = new PhotosContainerResource(albums, photos);
  data.transmogrify(config);
  Truth.assertThat(Iterables.get(data.getAlbums(),0).getName()).isEqualTo("This:a fake album!");
}
 
Example #23
Source File: ClassPathEntryTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetClassNames() throws IOException, ArtifactResolutionException {
  // copy into the local repository so we can read the jar file
  Artifact artifact = resolveArtifact("com.google.truth.extensions:truth-java8-extension:1.0.1");
  
  ClassPathEntry entry = new ClassPathEntry(artifact);
  ImmutableSet<String> classFileNames = entry.getFileNames();
  
  Truth.assertThat(classFileNames).containsExactly(
      "com.google.common.truth.IntStreamSubject",
      "com.google.common.truth.LongStreamSubject",
      "com.google.common.truth.OptionalDoubleSubject",
      "com.google.common.truth.OptionalSubject",
      "com.google.common.truth.OptionalIntSubject",
      "com.google.common.truth.OptionalLongSubject",
      "com.google.common.truth.PathSubject",
      "com.google.common.truth.Truth8",
      "com.google.common.truth.StreamSubject");
}
 
Example #24
Source File: PerfMarkTest.java    From perfmark with Apache License 2.0 6 votes vote down vote up
@Test
public void attachTag_functionFailureObjectFailureSucceeds() {
  Storage.resetForTest();
  PerfMark.setEnabled(true);
  Object o =
      new Object() {
        @Override
        public String toString() {
          throw new RuntimeException("worse");
        }
      };

  PerfMark.attachTag(
      "name",
      o,
      v -> {
        throw new RuntimeException("bad");
      });

  List<Mark> marks = Storage.readForTest();
  Truth.assertThat(marks).hasSize(0);
}
 
Example #25
Source File: PerfMarkTest.java    From perfmark with Apache License 2.0 6 votes vote down vote up
@Test
public void attachTag_doubleFunctionFailureSucceeds() {
  Storage.resetForTest();
  PerfMark.setEnabled(true);

  PerfMark.attachTag(
      "name",
      "extra2",
      v -> {
        throw new RuntimeException("bad") {
          @Override
          public String toString() {
            throw new RuntimeException("worse");
          }
        };
      });

  List<Mark> marks = Storage.readForTest();
  Truth.assertThat(marks).hasSize(0);
}
 
Example #26
Source File: ExclusionFilesTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testParse_exceptionSystemId()
    throws URISyntaxException, SAXException, IOException, VerifierConfigurationException {
  String resourceName = "exclusion-sample-rules/source-method.xml";
  Path exclusionFile = absolutePathOfResource(resourceName);
  try {
    ExclusionFiles.parse(exclusionFile);
    fail();
  } catch (SAXParseException expected) {
    assertEquals(4, expected.getLineNumber());
    Truth.assertThat(expected.getSystemId()).endsWith(resourceName);
    String systemId = expected.getSystemId();
    Truth.assertThat(systemId).startsWith("file:");
    Truth.assertThat(systemId).endsWith(resourceName);
  }
}
 
Example #27
Source File: ClassPathBuilderTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolve() {

  Artifact grpcAuth = new DefaultArtifact("io.grpc:grpc-auth:1.15.1");

  ImmutableList<ClassPathEntry> classPath =
      classPathBuilder.resolve(ImmutableList.of(grpcAuth)).getClassPath();

  Truth.assertThat(classPath)
      .comparingElementsUsing(TestHelper.COORDINATES)
      .containsAtLeast(
          "io.grpc:grpc-auth:1.15.1", "com.google.auth:google-auth-library-credentials:0.9.0");
  classPath.forEach(
      path ->
          Truth.assertWithMessage("Every returned path should be an absolute path")
              .that(path.getJar().isAbsolute())
              .isTrue());
}
 
Example #28
Source File: ExclusionFilesTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testParse_targetPackage_unmatch()
    throws URISyntaxException, IOException, SAXException, VerifierConfigurationException {
  Path exclusionFile = absolutePathOfResource("exclusion-sample-rules/target-package.xml");

  ImmutableList<LinkageErrorMatcher> matchers = ExclusionFiles.parse(exclusionFile);
  Truth.assertThat(matchers).hasSize(1);
  LinkageErrorMatcher matcher = matchers.get(0);

  // Package com.googler is not a subpackage of com.google.
  SymbolProblem symbolProblemToMatch =
      new SymbolProblem(
          new MethodSymbol("com.googler.Foo", "methodA", "()Ljava.lang.String;", false),
          ErrorType.INACCESSIBLE_MEMBER,
          new ClassFile(new ClassPathEntry(Paths.get("dummy.jar")), "com.googler.Foo"));
  boolean result =
      matcher.match(
          symbolProblemToMatch,
          new ClassFile(
              new ClassPathEntry(Paths.get("dummy.jar")), "reactor.core.publisher.Traces"));
  assertFalse(result);
}
 
Example #29
Source File: PhotosContainerResourceTest.java    From data-transfer-project with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyTransmogrifyAlbums_stripName() throws Exception {
  TransmogrificationConfig config = new TransmogrificationConfig();
  List<PhotoAlbum> albums =
      ImmutableList.of(new PhotoAlbum("id1", "This:a fake album!   ", "This:a fake album!"));

  List<PhotoModel> photos =
      ImmutableList.of(
          new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1",
              false),
          new PhotoModel("Pic3", "http://fake.com/2.jpg", "A pic", "image/jpg", "p3", "id1",
              false),
          new PhotoModel(
              "Pic2", "https://fake.com/pic.png", "fine art", "image/png", "p2", null, false));

  PhotosContainerResource data = new PhotosContainerResource(albums, photos);
  data.transmogrify(config);
  Truth.assertThat(Iterables.get(data.getAlbums(),0).getName()).isEqualTo("This:a fake album!");
}
 
Example #30
Source File: DependencyGraphIntegrationTest.java    From cloud-opensource-java with Apache License 2.0 6 votes vote down vote up
@Test
// a non-Google dependency graph that's well understood and thus useful for debugging
public void testJaxen() {

  DefaultArtifact jaxen = new DefaultArtifact("jaxen:jaxen:1.1.6");
  DependencyGraph graph =
      dependencyGraphBuilder.buildFullDependencyGraph(ImmutableList.of(jaxen));

  List<Update> updates = graph.findUpdates();
  Truth.assertThat(updates).hasSize(6);

  List<DependencyPath> conflicts = graph.findConflicts();
  Truth.assertThat(conflicts).hasSize(10);

  Map<String, String> versions = graph.getHighestVersionMap();
  Assert.assertEquals("2.6.2", versions.get("xerces:xercesImpl"));
}