org.hamcrest.text.MatchesPattern Java Examples

The following examples show how to use org.hamcrest.text.MatchesPattern. 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: ProtobufStatisticsSinkTest.java    From garmadon with Apache License 2.0 6 votes vote down vote up
@Test
public void sectionOneProperty() {
    ProtobufStatisticsSink sink = new ProtobufStatisticsSink();
    sink.beginSection("foo");
    sink.add("name", "value");
    sink.endSection();

    Pattern expected = Pattern.compile(
            "section \\{\n" +
            "  name: \"foo\"\n" +
            "  property \\{\n" +
            "    name: \"name\"\n" +
            "    value: \"value\"\n" +
            "  }\n" +
            "}\n", Pattern.DOTALL);
    String actual = sink.flush().toString();
    MatcherAssert.assertThat(actual, MatchesPattern.matchesPattern(expected));
}
 
Example #2
Source File: ProtobufGCNotificationsTest.java    From garmadon with Apache License 2.0 6 votes vote down vote up
@Test
public void getGCNotificationWithInfos() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(1);
    ProtobufGCNotifications notif = new ProtobufGCNotifications();
    notif.subscribe((timestamp, stats) -> {
        JsonFormat.Printer printer = JsonFormat.printer()
                .includingDefaultValueFields()
                .preservingProtoFieldNames();
        try {
            String s = printer.print((MessageOrBuilder) stats);
            MatcherAssert.assertThat(s, MatchesPattern.matchesPattern(GC_PATTERN));
            latch.countDown();
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
        }
    });
    System.gc();
    Assert.assertTrue(latch.await(1000, TimeUnit.MILLISECONDS));
}
 
Example #3
Source File: ScopeImplDumpTest.java    From toothpick with Apache License 2.0 6 votes vote down vote up
@Test
public void testToString() {
  // GIVEN
  ScopeImpl scope = new ScopeImpl("root");
  scope.installModules(new TestModule1());
  ScopeImpl childScope = new ScopeImpl("child");
  scope.addChild(childScope);

  // WHEN
  childScope.getInstance(Bar.class);
  String dump = scope.toString();

  // THEN
  Pattern expected =
      Pattern.compile(
          "root:\\d+.*"
              + "Providers: \\[toothpick.Scope,toothpick.data.Foo\\].*"
              + "\\\\---child:\\d+.*"
              + "Providers:.*\\[toothpick.Scope\\].*"
              + "UnScoped providers: \\[toothpick.data.Bar\\].*",
          Pattern.DOTALL);
  assertThat(dump, MatchesPattern.matchesPattern(expected));
}
 
Example #4
Source File: ExportFileTest.java    From buck with Apache License 2.0 6 votes vote down vote up
@Test
public void testDirectoryActionFailOnDirectory() throws Exception {
  ActionGraphBuilder graphBuilder = new TestActionGraphBuilder();
  expectedException.expect(HumanReadableException.class);
  expectedException.expectMessage(
      MatchesPattern.matchesPattern("Trying to export a directory .* but it is not allowed."));

  Path sourceDir = Paths.get("dir");
  projectFilesystem.mkdirs(sourceDir);
  ExportFile exportFile =
      new ExportFileBuilder(
              FakeBuckConfig.builder()
                  .setSections("[export_file]", "input_directory_action = fail")
                  .build(),
              target)
          .setOut("out")
          .setSrc(FakeSourcePath.of(projectFilesystem, sourceDir))
          .build(graphBuilder, projectFilesystem);

  exportFile.getBuildSteps(
      FakeBuildContext.withSourcePathResolver(graphBuilder.getSourcePathResolver())
          .withBuildCellRootPath(projectFilesystem.getRootPath().getPath()),
      new FakeBuildableContext());
}
 
Example #5
Source File: ProtobufStatisticsSinkTest.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@Test
public void singlePropertyOnly() {
    ProtobufStatisticsSink sink = new ProtobufStatisticsSink();
    sink.add("foo", "bar");
    Pattern expected = Pattern.compile(
            "section \\{\n" +
            "  property \\{\n" +
            "    name: \"foo\"\n" +
            "    value: \"bar\"\n" +
            "  }\n" +
            "}\n", Pattern.DOTALL);
    String actual = sink.flush().toString();
    MatcherAssert.assertThat(actual, MatchesPattern.matchesPattern(expected));
}
 
Example #6
Source File: ProtobufStatisticsSinkTest.java    From garmadon with Apache License 2.0 5 votes vote down vote up
@Test
public void emptySection() {
    ProtobufStatisticsSink sink = new ProtobufStatisticsSink();
    sink.beginSection("foo");
    sink.endSection();
    Pattern expected = Pattern.compile(
            "section \\{\n" +
            "  name: \"foo\"\n" +
            "}\n", Pattern.DOTALL);
    String actual = sink.flush().toString();
    MatcherAssert.assertThat(actual, MatchesPattern.matchesPattern(expected));
}
 
Example #7
Source File: ExportFileTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testDirectoryActionWarnOnDirectory() throws Exception {
  ActionGraphBuilder graphBuilder = new TestActionGraphBuilder();

  Path sourceDir = Paths.get("dir");
  projectFilesystem.mkdirs(sourceDir);
  ExportFile exportFile =
      new ExportFileBuilder(
              FakeBuckConfig.builder()
                  .setSections("[export_file]", "input_directory_action = warn")
                  .build(),
              target)
          .setOut("out")
          .setSrc(FakeSourcePath.of(projectFilesystem, sourceDir))
          .build(graphBuilder, projectFilesystem);

  BuckEventBus buckEventBus = BuckEventBusForTests.newInstance();
  CapturingConsoleEventListener listener = new CapturingConsoleEventListener();
  buckEventBus.register(listener);

  exportFile.getBuildSteps(
      FakeBuildContext.create(graphBuilder.getSourcePathResolver(), buckEventBus)
          .withBuildCellRootPath(projectFilesystem.getRootPath().getPath()),
      new FakeBuildableContext());

  assertThat(
      listener.getLogMessages().get(0),
      MatchesPattern.matchesPattern("Trying to export a directory .* but it is not allowed."));
}
 
Example #8
Source File: ProtobufStatisticsSinkTest.java    From garmadon with Apache License 2.0 4 votes vote down vote up
@Test
public void properties() {
    ProtobufStatisticsSink sink = new ProtobufStatisticsSink();
    sink.beginSection("section");
    sink.add("strName", "strValue");
    sink.add("intName", Integer.MAX_VALUE);
    sink.add("longName", Long.MAX_VALUE);
    sink.addDuration("durationName", 42);
    sink.addPercentage("percentageName", 100);
    sink.addSize("sizeName", 1025);
    sink.endSection();
    Pattern expected = Pattern.compile(
            "section \\{\n" +
            "  name: \"section\"\n" +
            "  property \\{\n" +
            "    name: \"strName\"\n" +
            "    value: \"strValue\"\n" +
            "  }\n" +
            "  property \\{\n" +
            "    name: \"intName\"\n" +
            "    value: \"2147483647\"\n" +
            "  }\n" +
            "  property \\{\n" +
            "    name: \"longName\"\n" +
            "    value: \"9223372036854775807\"\n" +
            "  }\n" +
            "  property \\{\n" +
            "    name: \"durationName\"\n" +
            "    value: \"42\"\n" +
            "  }\n" +
            "  property \\{\n" +
            "    name: \"%percentageName\"\n" +
            "    value: \"100.0\"\n" +
            "  }\n" +
            "  property \\{\n" +
            "    name: \"sizeName\"\n" +
            "    value: \"1\"\n" +
            "  }\n" +
            "}\n", Pattern.DOTALL);
    String actual = sink.flush().toString();
    MatcherAssert.assertThat(actual, MatchesPattern.matchesPattern(expected));
    // flush should have call reset
    assertThat(sink.flush().toString(), MatchesPattern.matchesPattern(""));
}
 
Example #9
Source File: AppIconsTest.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
private void assertIconUrl(String expectedUrl) {
    App app = AppProvider.Helper.findHighestPriorityMetadata(context.getContentResolver(),
            "org.adaway", new String[]{
                    Schema.AppMetadataTable.Cols.ICON_URL,
                    Schema.AppMetadataTable.Cols.ICON,
                    Schema.AppMetadataTable.Cols.REPO_ID,
            });
    assertThat(app.getIconUrl(context), MatchesPattern.matchesPattern(expectedUrl));
}