org.hamcrest.comparator.ComparatorMatcherBuilder Java Examples

The following examples show how to use org.hamcrest.comparator.ComparatorMatcherBuilder. 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: SitePresenceCompareTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void nullSafeCompare() {
    Assert.assertThat(presenceC, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().comparesEqualTo(presenceC));
    Assert.assertThat(presenceB, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().lessThan(presenceC));
    Assert.assertThat(presenceC, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().greaterThan(presenceB));

    Assert.assertThat(presenceD, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().comparesEqualTo(presenceD));
    Assert.assertThat(presenceB, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().lessThan(presenceD));
    Assert.assertThat(presenceD, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().greaterThan(presenceB));

    Assert.assertThat(presenceE, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().comparesEqualTo(presenceE));
    Assert.assertThat(presenceB, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().lessThan(presenceE));
    Assert.assertThat(presenceE, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().greaterThan(presenceB));

    Assert.assertThat(presenceD, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().lessThan(presenceE));
}
 
Example #2
Source File: SitePresenceCompareTest.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
@Test
public void nullSafeCompare() {
    Assert.assertThat(presenceC, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().comparesEqualTo(presenceC));
    Assert.assertThat(presenceB, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().lessThan(presenceC));
    Assert.assertThat(presenceC, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().greaterThan(presenceB));

    Assert.assertThat(presenceD, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().comparesEqualTo(presenceD));
    Assert.assertThat(presenceB, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().lessThan(presenceD));
    Assert.assertThat(presenceD, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().greaterThan(presenceB));

    Assert.assertThat(presenceE, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().comparesEqualTo(presenceE));
    Assert.assertThat(presenceB, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().lessThan(presenceE));
    Assert.assertThat(presenceE, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().greaterThan(presenceB));

    Assert.assertThat(presenceD, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().lessThan(presenceE));
}
 
Example #3
Source File: PythonBinaryIntegrationTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void compileSources() throws IOException, InterruptedException {
  assumeThat(packageStyle, is(PackageStyle.STANDALONE));
  Path py3 = PythonTestUtils.assumeInterpreter("python3");
  PythonTestUtils.assumeVersion(
      py3,
      Matchers.any(String.class),
      ComparatorMatcherBuilder.comparedBy(new VersionStringComparator())
          .greaterThanOrEqualTo("3.7"));
  Path binPath =
      workspace.buildAndReturnOutput("-c", "python.interpreter=" + py3, "//:bin_compile");
  ImmutableSet<Path> paths =
      pexDirectory
          ? Files.walk(binPath)
              .filter(p -> !p.equals(binPath))
              .map(binPath::relativize)
              .collect(ImmutableSet.toImmutableSet())
          : Unzip.getZipMembers(binPath);
  assertThat(
      paths.stream().map(PathFormatter::pathWithUnixSeparators).collect(Collectors.toList()),
      Matchers.hasItems(
          Matchers.matchesRegex("foo/bar/(__pycache__/)?mod(.cpython-3[0-9])?.pyc"),
          Matchers.matchesRegex("(__pycache__/)?main(.cpython-3[0-9])?.pyc")));
}
 
Example #4
Source File: PythonLibraryIntegrationTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void compile() throws Exception {
  Path py3 = PythonTestUtils.assumeInterpreter("python3");
  PythonTestUtils.assumeVersion(
      py3,
      Matchers.any(String.class),
      ComparatorMatcherBuilder.comparedBy(new VersionStringComparator())
          .greaterThanOrEqualTo("3.7"));
  workspace =
      TestDataHelper.createProjectWorkspaceForScenario(this, "python_library_compile", tmp);
  workspace.setUp();
  ProjectFilesystem filesystem = workspace.getProjectFileSystem();
  RelPath dir =
      filesystem.relativize(
          workspace.buildAndReturnOutput(
              "-c", "python.interpreter=" + py3, "//:lib#py-default,default,compile"));
  assertThat(
      filesystem.asView().getFilesUnderPath(dir.getPath(), EnumSet.noneOf(FileVisitOption.class))
          .stream()
          .map(p -> PathFormatter.pathWithUnixSeparators(dir.getPath().relativize(p)))
          .collect(ImmutableList.toImmutableList()),
      Matchers.containsInAnyOrder(
          Matchers.matchesRegex("(__pycache__/)?foo(.cpython-3[0-9])?.pyc")));
}
 
Example #5
Source File: PrebuiltPythonLibraryIntegrationTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void compile() throws IOException, InterruptedException {
  Path py3 = PythonTestUtils.assumeInterpreter("python3");
  PythonTestUtils.assumeVersion(
      py3,
      Matchers.any(String.class),
      ComparatorMatcherBuilder.comparedBy(new VersionStringComparator())
          .greaterThanOrEqualTo("3.7"));
  ProjectFilesystem filesystem = workspace.getProjectFileSystem();
  RelPath dir =
      filesystem.relativize(
          workspace.buildAndReturnOutput(
              "-c", "python.interpreter=" + py3, "//:python_egg#py-default,default,compile"));
  assertThat(
      filesystem.asView().getFilesUnderPath(dir.getPath(), EnumSet.noneOf(FileVisitOption.class))
          .stream()
          .map(p -> PathFormatter.pathWithUnixSeparators(dir.getPath().relativize(p)))
          .collect(ImmutableList.toImmutableList()),
      Matchers.containsInAnyOrder(
          Matchers.matchesRegex("package(/__pycache__)?/file(.cpython-3[0-9])?.pyc"),
          Matchers.matchesRegex("package(/__pycache__)?/__init__(.cpython-3[0-9])?.pyc")));
}
 
Example #6
Source File: SitePresenceCompareTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test
public void safeCompare() {
    Assert.assertThat(presenceA, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().comparesEqualTo(presenceA));
    Assert.assertThat(presenceB, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().comparesEqualTo(presenceB));
    Assert.assertThat(presenceA, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().lessThan(presenceB));
    Assert.assertThat(presenceB, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().greaterThan(presenceA));
}
 
Example #7
Source File: SitePresenceCompareTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test
public void safeCompare() {
    Assert.assertThat(presenceA, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().comparesEqualTo(presenceA));
    Assert.assertThat(presenceB, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().comparesEqualTo(presenceB));
    Assert.assertThat(presenceA, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().lessThan(presenceB));
    Assert.assertThat(presenceB, ComparatorMatcherBuilder.<SitePresence>usingNaturalOrdering().greaterThan(presenceA));
}
 
Example #8
Source File: PythonLibraryIntegrationTest.java    From buck with Apache License 2.0 4 votes vote down vote up
@Test
public void compileDeterminism() throws Exception {
  Path py3 = PythonTestUtils.assumeInterpreter("python3");
  PythonTestUtils.assumeVersion(
      py3,
      Matchers.any(String.class),
      ComparatorMatcherBuilder.comparedBy(new VersionStringComparator())
          .greaterThanOrEqualTo("3.7"));
  workspace =
      TestDataHelper.createProjectWorkspaceForScenario(this, "python_library_compile", tmp);
  workspace.setUp();
  ProjectFilesystem filesystem = workspace.getProjectFileSystem();
  String target = "//:lib#py-default,default,compile";

  // A supplier which uses Buck to compile bytecode and return the content hashes.
  ThrowingSupplier<Map<Path, Sha1HashCode>, IOException> buildAndGetHashes =
      () -> {
        RelPath dir =
            filesystem.relativize(
                workspace.buildAndReturnOutput(
                    // Generate some randomness to encourage this test to fail if propagated
                    // through.
                    ImmutableMap.of("PYTHONHASHSEED", "random"),
                    "-c",
                    "python.interpreter=" + py3,
                    "//:lib#py-default,default,compile"));
        Map<Path, Sha1HashCode> hashes = new HashMap<>();
        for (Path path :
            filesystem
                .asView()
                .getFilesUnderPath(dir.getPath(), EnumSet.noneOf(FileVisitOption.class))) {
          hashes.put(path, filesystem.computeSha1(path));
        }
        workspace.getBuildLog().assertTargetBuiltLocally(target);
        workspace.runBuckCommand("clean");
        return hashes;
      };

  // Verify that running the compilation multiple times yeilds the same results.
  assertThat(
      Stream.generate(buildAndGetHashes.asSupplier())
          .limit(10)
          .distinct()
          .collect(Collectors.toList()),
      Matchers.hasSize(1));
}