android.view.MotionEvent.PointerCoords#com.google.common.truth.Truth源码实例Demo

下面列出了android.view.MotionEvent.PointerCoords#com.google.common.truth.Truth 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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);
}
 
@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);
}
 
@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);
}
 
@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();
}
 
@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);
}
 
@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");
}
 
@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);
}
 
/**
 * Javadoc.
 */
@Parameters(name = "class={0}")
public static Collection<Object[]> params() throws Exception {
  ClassLoader loader = ChannelAndServerBuilderTest.class.getClassLoader();
  Collection<ClassInfo> classInfos =
      ClassPath.from(loader).getTopLevelClassesRecursive("io.grpc");
  // Java 9 doesn't expose the URLClassLoader, which breaks searching through the classpath
  if (classInfos.isEmpty()) {
    return new ArrayList<Object[]>();
  }
  List<Object[]> classes = new ArrayList<Object[]>();
  for (ClassInfo classInfo : classInfos) {
    Class<?> clazz = Class.forName(classInfo.getName(), false /*initialize*/, loader);
    if (ServerBuilder.class.isAssignableFrom(clazz) && clazz != ServerBuilder.class) {
      classes.add(new Object[]{clazz});
    } else if (ManagedChannelBuilder.class.isAssignableFrom(clazz)
        && clazz != ManagedChannelBuilder.class) {
      classes.add(new Object[]{clazz});
    }
  }
  Truth.assertWithMessage("Unable to find any builder classes").that(classes).isNotEmpty();
  return classes;
}
 
@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);
}
 
源代码10 项目: cloud-opensource-java   文件: LinkageCheckerTest.java
@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");
}
 
源代码11 项目: cloud-opensource-java   文件: ClassDumperTest.java
@Test
public void testListClasses_unexpectedNonClassFile() throws IOException {
  // com.amazonaws:amazon-kinesis-client:1.13.0 contains an unexpected lock file
  // /unison/com/e007f77498fd27177e2ea931a06dcf50/unison/tmp/amazonaws/services/kinesis/leases/impl/LeaseTaker.class
  // https://github.com/awslabs/amazon-kinesis-client/issues/654
  List<ClassPathEntry> classPath = resolvePaths("com.amazonaws:amazon-kinesis-client:1.13.0");
  ClassDumper classDumper = ClassDumper.create(classPath);
  ClassPathEntry kinesisJar = classPath.get(0);

  // This should not raise IOException
  SymbolReferences symbolReferences = classDumper.findSymbolReferences();

  Truth.assertWithMessage("Invalid files should not stop loading valid class files")
      .that(symbolReferences.getClassFiles())
      .comparingElementsUsing(
          Correspondence.transforming(
              (ClassFile classFile) -> classFile.getClassPathEntry(), "is in the JAR file"))
      .contains(kinesisJar);
}
 
@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");
}
 
@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");
}
 
源代码14 项目: cloud-opensource-java   文件: LinkageCheckerTest.java
@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"));
}
 
@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!");
}
 
源代码16 项目: perfmark   文件: PerfMarkTest.java
@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);
}
 
源代码17 项目: perfmark   文件: PerfMarkTest.java
@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);
}
 
源代码18 项目: cloud-opensource-java   文件: ExclusionFilesTest.java
@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);
  }
}
 
@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());
}
 
@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!");
}
 
@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"));
}
 
源代码22 项目: cloud-opensource-java   文件: ExclusionFilesTest.java
@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);
}
 
源代码23 项目: cloud-opensource-java   文件: ClassPathEntryTest.java
@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");
}
 
@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);
}
 
源代码25 项目: cloud-opensource-java   文件: LinkageCheckerTest.java
@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();
}
 
@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());
  }
}
 
@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");
}
 
@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());
}
 
源代码29 项目: cloud-opensource-java   文件: ClassDumperTest.java
@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();
  }
}
 
@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);
}