当前位置: 首页>>代码示例>>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;未经允许,请勿转载。