當前位置: 首頁>>代碼示例>>Java>>正文


Java Matchers類代碼示例

本文整理匯總了Java中org.hamcrest.Matchers的典型用法代碼示例。如果您正苦於以下問題:Java Matchers類的具體用法?Java Matchers怎麽用?Java Matchers使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Matchers類屬於org.hamcrest包,在下文中一共展示了Matchers類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSortWithFk

import org.hamcrest.Matchers; //導入依賴的package包/類
@Test
public void testSortWithFk() throws Exception {
    final ExecuteChangeCommand aTab1 = newIncrementalCommand(tableChangeType(), "ATab", "1", Sets.immutable.<String>of(), 1);
    final ExecuteChangeCommand aTab2 = newIncrementalCommand(tableChangeType(), "ATab", "2", Sets.immutable.<String>of(), 2);
    final ExecuteChangeCommand aTab3 = newIncrementalCommand(tableChangeType(), "ATab", "3", Sets.immutable.<String>of(), 3);
    final ExecuteChangeCommand bTab1 = newIncrementalCommand(tableChangeType(), "BTab", "1", Sets.immutable.<String>of(), 1);
    final ExecuteChangeCommand bTab2 = newIncrementalCommand(tableChangeType(), "BTab", "2", Sets.immutable.<String>of("ATab"), 2);
    final ExecuteChangeCommand bTab3 = newIncrementalCommand(tableChangeType(), "BTab", "3", Sets.immutable.<String>of(), 3);
    final ListIterable<ExecuteChangeCommand> sortedCommands = sorter.sort(Lists.mutable.of(
            aTab1
            , aTab2
            , aTab3
            , bTab1
            , bTab2
            , bTab3
    ), false);

    // assert basic order
    assertThat("aTab changes should be in order", sortedCommands.indexOf(aTab1), Matchers.lessThan(sortedCommands.indexOf(aTab2)));
    assertThat("aTab changes should be in order", sortedCommands.indexOf(aTab2), Matchers.lessThan(sortedCommands.indexOf(aTab3)));
    assertThat("bTab changes should be in order", sortedCommands.indexOf(bTab1), Matchers.lessThan(sortedCommands.indexOf(bTab2)));
    assertThat("bTab changes should be in order", sortedCommands.indexOf(bTab2), Matchers.lessThan(sortedCommands.indexOf(bTab3)));

    // assert cross-object dependency
    assertThat("assert bTab change depending on aTab comes after tabA", sortedCommands.indexOf(aTab1), Matchers.lessThan(sortedCommands.indexOf(bTab2)));
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:27,代碼來源:ChangeCommandSorterImplTest.java

示例2: can_evaluate_pathed_datetime_against_current_datetime_minus_12_month

import org.hamcrest.Matchers; //導入依賴的package包/類
@Test
public void can_evaluate_pathed_datetime_against_current_datetime_minus_12_month() throws Exception {
    // /data[at0001]/items[at0003]/value/value>=($currentDateTime.value-12,mo)
    DataInstance[] dataInstances = new DataInstance[1];
    dataInstances[0] = new DataInstance.Builder()
            .modelId("weight")
            .addValue("/data[at0001]/items[at0003]", DvDateTime.valueOf("2014-02-15T18:18:00"))
            .build();
    interpreter = new Interpreter(DvDateTime.valueOf("2015-01-10T00:00:00"));
    BinaryExpression binaryExpression = new BinaryExpression(
            new Variable(CURRENT_DATETIME, null, null, "value"),
            new QuantityConstant(new DvQuantity("mo", 12.0, 0)), OperatorKind.SUBTRACTION);
    BinaryExpression predicate = new BinaryExpression(Variable.createByPath("/data[at0001]/items[at0003]/value/value"),
            binaryExpression, OperatorKind.GREATER_THAN_OR_EQUAL);
    List<DataInstance> result = interpreter.evaluateDataInstancesWithPredicate(Arrays.asList(dataInstances), predicate, null);
    assertThat(result.size(), Matchers.is(1));
    assertThat(result.get(0).modelId(), is("weight"));
}
 
開發者ID:gdl-lang,項目名稱:gdl2,代碼行數:19,代碼來源:PredicateTest.java

示例3: equalsAndHashCode

import org.hamcrest.Matchers; //導入依賴的package包/類
/**
 * Make sure that equals and hash code are reflexive
 * and symmetric.
 */
@Test
public void equalsAndHashCode() {
    final String val = "test scalar value";
    final Scalar firstScalar = new Scalar(val);
    final Scalar secondScalar = new Scalar(val);

    MatcherAssert.assertThat(firstScalar, Matchers.equalTo(secondScalar));
    MatcherAssert.assertThat(secondScalar, Matchers.equalTo(firstScalar));

    MatcherAssert.assertThat(firstScalar, Matchers.equalTo(firstScalar));
    MatcherAssert.assertThat(firstScalar,
        Matchers.not(Matchers.equalTo(null)));

    MatcherAssert.assertThat(
        firstScalar.hashCode() == secondScalar.hashCode(), is(true)
    );
}
 
開發者ID:decorators-squad,項目名稱:camel,代碼行數:22,代碼來源:ScalarTest.java

示例4: testStatusWithoutSummary

import org.hamcrest.Matchers; //導入依賴的package包/類
@Test
public void testStatusWithoutSummary() {
	Collection<AppStatusResource> data = new ArrayList<>();
	data.add(appStatusResource1);
	data.add(appStatusResource2);
	PagedResources.PageMetadata metadata = new PagedResources.PageMetadata(data.size(), 1, data.size(), 1);
	PagedResources<AppStatusResource> result = new PagedResources<>(data, metadata);
	when(runtimeOperations.status()).thenReturn(result);
	Object[][] expected = new String[][] {
			{"1", "deployed", "2"},
			{"10", "deployed"},
			{"20", "deployed"},
			{"2", "undeployed", "0"}
	};
	TableModel model = runtimeCommands.list(false, null).getModel();
	for (int row = 0; row < expected.length; row++) {
		for (int col = 0; col < expected[row].length; col++) {
			assertThat(String.valueOf(model.getValue(row + 1, col)), Matchers.is(expected[row][col]));
		}
	}
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-dashboard,代碼行數:22,代碼來源:RuntimeCommandsTests.java

示例5: testParsingFormattedStringWithOffsetToOffsetDateTime

import org.hamcrest.Matchers; //導入依賴的package包/類
@Test
public final void testParsingFormattedStringWithOffsetToOffsetDateTime() {
    MatcherAssert.assertThat(
        "Can't parse a OffsetDateTime with custom format.",
        new OffsetDateTimeOf(
            "2017-12-13 14:15:16",
            "yyyy-MM-dd HH:mm:ss",
            ZoneOffset.ofHours(1)
        ).value(),
        Matchers.is(
            OffsetDateTime.of(
                LocalDateTime.of(2017, 12, 13, 14, 15, 16),
                ZoneOffset.ofHours(1)
            )
        )
    );
}
 
開發者ID:yegor256,項目名稱:cactoos,代碼行數:18,代碼來源:OffsetDateTimeOfTest.java

示例6: testEmptyAggregation

import org.hamcrest.Matchers; //導入依賴的package包/類
public void testEmptyAggregation() throws Exception {
    SearchResponse searchResponse = client().prepareSearch("empty_bucket_idx")
            .setQuery(matchAllQuery())
            .addAggregation(histogram("histo").field("value").interval(1L).minDocCount(0)
                    .subAggregation(dateHistogram("date_histo").field("value").interval(1)))
            .execute().actionGet();

    assertThat(searchResponse.getHits().getTotalHits(), equalTo(2L));
    Histogram histo = searchResponse.getAggregations().get("histo");
    assertThat(histo, Matchers.notNullValue());
    List<? extends Histogram.Bucket> buckets = histo.getBuckets();
    assertThat(buckets.size(), equalTo(3));

    Histogram.Bucket bucket = buckets.get(1);
    assertThat(bucket, Matchers.notNullValue());
    assertThat(bucket.getKeyAsString(), equalTo("1.0"));

    Histogram dateHisto = bucket.getAggregations().get("date_histo");
    assertThat(dateHisto, Matchers.notNullValue());
    assertThat(dateHisto.getName(), equalTo("date_histo"));
    assertThat(dateHisto.getBuckets().isEmpty(), is(true));

}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:24,代碼來源:DateHistogramIT.java

示例7: test

import org.hamcrest.Matchers; //導入依賴的package包/類
@Test
public void test() throws InstantiationException, IllegalAccessException {
	String url = getBaseUri() + "country/ch";
	io.restassured.response.Response getResponse = RestAssured.get(url);
	Assert.assertEquals(200, getResponse.getStatusCode());

	getResponse.then().assertThat().body("data.attributes.deText", Matchers.equalTo("Schweiz"));
	getResponse.then().assertThat().body("data.attributes.enText", Matchers.equalTo("Switzerland"));

	String patchData = "{'data':{'id':'ch','type':'country','attributes':{'deText':'Test','enText':'Switzerland','ctlActCd':true}}}".replaceAll("'", "\"");

	Response patchResponse = RestAssured.given().body(patchData.getBytes()).header("content-type", JsonApiMediaType.APPLICATION_JSON_API).when().patch(url);
	patchResponse.then().statusCode(HttpStatus.SC_OK);

	getResponse = RestAssured.get(url);
	Assert.assertEquals(200, getResponse.getStatusCode());
	getResponse.then().assertThat().body("data.attributes.deText", Matchers.equalTo("Test"));
	getResponse.then().assertThat().body("data.attributes.enText", Matchers.equalTo("Switzerland"));
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:20,代碼來源:CustomResourceFieldTest.java

示例8: startsUnknownCommand

import org.hamcrest.Matchers; //導入依賴的package包/類
/**
 * Confused can start an 'unknown' command.
 * @throws Exception If something goes wrong.
 */
@Test
public void startsUnknownCommand() throws Exception {
    final Command com = Mockito.mock(Command.class);
    Mockito.when(com.type()).thenReturn("unknown");
    Mockito.when(com.language()).thenReturn(new English());

    final Knowledge confused = new Confused();

    Steps steps = confused.start(com, Mockito.mock(Log.class));
    MatcherAssert.assertThat(steps, Matchers.notNullValue());
    MatcherAssert.assertThat(
        steps instanceof GithubSteps, Matchers.is(true)
    );

}
 
開發者ID:amihaiemil,項目名稱:comdor,代碼行數:20,代碼來源:ConfusedTestCase.java

示例9: iteratedCorrectlyBetweenBlankSheet

import org.hamcrest.Matchers; //導入依賴的package包/類
@Ignore
@Test
public void iteratedCorrectlyBetweenBlankSheet() throws IOException {
    MatcherAssert.assertThat(
        "Each rows are iterated correctly, between blank sheets",
        new IteratorIterable<>(
            new ExcelIterator(
                new XSSFWorkbook(
                    new ResourceAsStream("excel/test-between-blank-sheet.xlsx").stream()
                )
            )
        ),
        Matchers.contains(
            Matchers.is("jed,24.0"),
            Matchers.is("aisyl,20.0"),
            Matchers.is("linux,23.0"),
            Matchers.is("juan,29.0")
        )
    );
}
 
開發者ID:jedcua,項目名稱:Parseux,代碼行數:21,代碼來源:ExcelIteratorTest.java

示例10: mapResponse_withHeaders

import org.hamcrest.Matchers; //導入依賴的package包/類
@Test
public void mapResponse_withHeaders() {
  MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
  headers.add("h", "v");

  new Expectations() {
    {
      jaxrsResponse.getStatusInfo();
      result = Status.OK;
      jaxrsResponse.getEntity();
      result = "result";
      jaxrsResponse.getHeaders();
      result = headers;
    }
  };
  Response response = mapper.mapResponse(null, jaxrsResponse);
  Assert.assertEquals(Status.OK, response.getStatus());
  Assert.assertEquals("result", response.getResult());
  Assert.assertEquals(1, response.getHeaders().getHeaderMap().size());
  Assert.assertThat(response.getHeaders().getHeader("h"), Matchers.contains("v"));
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:22,代碼來源:TestJaxrsProducerResponseMapper.java

示例11: testAgentHeapAllocation

import org.hamcrest.Matchers; //導入依賴的package包/類
@Test
public void testAgentHeapAllocation() throws Exception {
  final Process process = createProcessBuilder(heapDumpFolder) //
      .withJvmArgument("-Xms8m") //
      .withJvmArgument("-Xmx8m") //
      .withSystemProperty(LOG_LEVEL, "ERROR") //
      .withSystemProperty(CHECK_INTERVAL, "1s") //
      .withSystemProperty(MAX_HEAP_DUMP_FREQUENCY, "1/3s") //
      .withSystemProperty(HEAP_MEMORY_USAGE_THRESHOLD, "1%") //
      .withSystemProperty("jma-test.mode", "direct_allocation") //
      .withSystemProperty("jma-test.allocation", "3MB") //
      .withSystemProperty("jma-test.log", "false") //
      .buildAndRunUntil(heapDumpCreatedIn(heapDumpFolder, 1, TimeUnit.MINUTES));

  assertThat(process.getErr(), hasNoErrors());
  assertThat(heapDumpFolder.listFiles(), is(not(Matchers.<File>emptyArray())));
}
 
開發者ID:SAP,項目名稱:java-memory-assistant,代碼行數:18,代碼來源:E2eITest.java

示例12: valid

import org.hamcrest.Matchers; //導入依賴的package包/類
@Test
public void valid()
    throws InvalidDataException, IOException, UnsupportedTagException {
    final Path path = Paths.get("src/test/resources/album/test.mp3");
    MatcherAssert.assertThat(
        new AdvancedTagVerifiedAlbumImage(
            new AdvancedTagFromMp3File(
                new Mp3File(
                    path.toFile()
                )
            )
        ).construct().getAlbumImage(),
        Matchers.equalTo(
            Files.readAllBytes(this.image)
        )
    );
}
 
開發者ID:driver733,項目名稱:VKMusicUploader,代碼行數:18,代碼來源:AdvancedTagVerifiedAlbumImageTest.java

示例13: returnsNullOnMissingKey

import org.hamcrest.Matchers; //導入依賴的package包/類
/**
 * RtYamlMapping can return null if the specified key is missig.
 */
@Test
public void returnsNullOnMissingKey() {
    Map<YamlNode, YamlNode> mappings = new HashMap<>();
    mappings.put(new Scalar("key3"), Mockito.mock(YamlSequence.class));
    mappings.put(new Scalar("key1"), Mockito.mock(YamlMapping.class));
    RtYamlMapping map = new RtYamlMapping(mappings);
    MatcherAssert.assertThat(
        map.yamlSequence("key4"), Matchers.nullValue()
    );
    MatcherAssert.assertThat(
        map.yamlMapping("key4"), Matchers.nullValue()
    );
    MatcherAssert.assertThat(
        map.string("key4"), Matchers.nullValue()
    );
    MatcherAssert.assertThat(
        map.yamlSequence("key1"), Matchers.nullValue()
    );
}
 
開發者ID:decorators-squad,項目名稱:camel,代碼行數:23,代碼來源:RtYamlMappingTest.java

示例14: testLogoutFailures

import org.hamcrest.Matchers; //導入依賴的package包/類
@Test
public void testLogoutFailures() throws Exception {
    // PHONE_INVALID_FORMAT
    mockMvc.perform(post(URI_USER_LOGOUT)
        .param("phoneNum", TEST_PHONE_INVALID)
        .session(session))
        .andExpect(status().isBadRequest())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
        .andExpect(jsonPath("$.*").value(Matchers.hasSize(2)))
        .andExpect(jsonPath("$.info").isString())
        .andExpect(jsonPath("$.code").value(100));
    // SESSION_NOT_FOUND
    mockMvc.perform(post(URI_USER_LOGOUT)
        .param("phoneNum", TEST_PHONE_USER))
        .andExpect(status().isForbidden())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
        .andExpect(jsonPath("$.*").value(Matchers.hasSize(2)))
        .andExpect(jsonPath("$.info").isString())
        .andExpect(jsonPath("$.code").value(403));
}
 
開發者ID:AwesomeTickets,項目名稱:ServiceServer,代碼行數:21,代碼來源:UserControllerTest.java

示例15: testParsingCustomFormattedStringToDate

import org.hamcrest.Matchers; //導入依賴的package包/類
@Test
public final void testParsingCustomFormattedStringToDate() {
    MatcherAssert.assertThat(
        "Can't parse a Date with custom format.",
        new DateOf(
            "2017-12-13 14:15:16.000000017",
            "yyyy-MM-dd HH:mm:ss.n"
        ).value(),
        Matchers.is(
            Date.from(
                LocalDateTime.of(
                    2017, 12, 13, 14, 15, 16, 17
                ).toInstant(ZoneOffset.UTC)
            )
        )
    );
}
 
開發者ID:yegor256,項目名稱:cactoos,代碼行數:18,代碼來源:DateOfTest.java


注:本文中的org.hamcrest.Matchers類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。