本文整理汇总了Java中org.hamcrest.CustomMatcher类的典型用法代码示例。如果您正苦于以下问题:Java CustomMatcher类的具体用法?Java CustomMatcher怎么用?Java CustomMatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CustomMatcher类属于org.hamcrest包,在下文中一共展示了CustomMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBadRepo
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
@Test
public void testBadRepo() throws Exception
{
expectedException.expect(new CustomMatcher<Object>(IllegalArgumentException.class.getName())
{
@Override
public boolean matches(Object item)
{
return item instanceof IllegalArgumentException;
}
});
new GSWagon()
{
public Repository getRepository()
{
return new Repository("id", "http://bucket/key");
}
}.openConnectionInternal();
}
示例2: checkRemoveAddress
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
private void checkRemoveAddress(boolean sniff) {
Object[] extraSettings = {TransportClient.CLIENT_TRANSPORT_SNIFF.getKey(), sniff};
try(TestIteration iteration = new TestIteration(extraSettings)) {
final TransportClientNodesService service = iteration.transportClientNodesService;
assertEquals(iteration.listNodesCount + iteration.sniffNodesCount, service.connectedNodes().size());
final TransportAddress addressToRemove = randomFrom(iteration.listNodeAddresses);
service.removeTransportAddress(addressToRemove);
assertThat(service.connectedNodes(), everyItem(not(new CustomMatcher<DiscoveryNode>("removed address") {
@Override
public boolean matches(Object item) {
return item instanceof DiscoveryNode && ((DiscoveryNode)item).getAddress().equals(addressToRemove);
}
})));
assertEquals(iteration.listNodesCount + iteration.sniffNodesCount - 1, service.connectedNodes().size());
}
}
示例3: sendTextMessage
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
@Test
public void sendTextMessage() {
// Setup
ExampleMessage message = ExampleMessage.createOutgoingTextMessage(TEST_CHAT_ID, "Hello world");
final MessageQueries.SendQuery<ExampleMessage> sendQuery = new MessageQueries.SendQuery<>(TEST_CHAT_ID, message);
final TestSubscriber<Update<ExampleMessage>> testSubscriber = new TestSubscriber<>();
// Execute
mUpdates.subscribe(testSubscriber);
mTarget.send(sendQuery).subscribe();
// Assert
verify(mMockParseHelper).save(argThat(new CustomMatcher<ParseObject>("") {
@Override
public boolean matches(Object item) {
final ParseObject parseMessage = (ParseObject) item;
return parseMessage.getClassName().equals(MessagesTable.NAME);
}
}));
testSubscriber.assertValueCount(2);
}
示例4: listsReadOnlyLabels
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
/**
* MkIssue can list its labels.
* @throws Exception If some problem inside
*/
@Test
public void listsReadOnlyLabels() throws Exception {
final Issue issue = this.issue();
final String tag = "test-tag";
issue.repo().labels().create(tag, "c0c0c0");
issue.labels().add(Collections.singletonList(tag));
MatcherAssert.assertThat(
new Issue.Smart(issue).roLabels().iterate(),
Matchers.<Label>hasItem(
new CustomMatcher<Label>("label just created") {
@Override
public boolean matches(final Object item) {
return Label.class.cast(item).name().equals(tag);
}
}
)
);
}
示例5: successful
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
public static Matcher<Response> successful() {
return new CustomMatcher<Response>("2xx family of successful responses") {
@Override
public boolean matches(Object o) {
return (o instanceof Response)
&& (((Response) o).getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL);
}
@Override
public void describeMismatch(Object item, Description description) {
Response response = (Response) item;
provideDescription(response, description);
}
};
}
示例6: clientError
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
public static Matcher<Response> clientError() {
return new CustomMatcher<Response>("4xx (client error) family of responses") {
@Override
public boolean matches(Object o) {
return (o instanceof Response)
&& (((Response) o).getStatusInfo().getFamily() == Response.Status.Family.CLIENT_ERROR);
}
@Override
public void describeMismatch(Object item, Description description) {
Response response = (Response) item;
provideDescription(response, description);
}
};
}
示例7: redirection
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
public static Matcher<Response> redirection() {
return new CustomMatcher<Response>("3xx (redirection) family of responses") {
@Override
public boolean matches(Object o) {
return (o instanceof Response)
&& (((Response) o).getStatusInfo().getFamily() == Response.Status.Family.REDIRECTION);
}
@Override
public void describeMismatch(Object item, Description description) {
Response response = (Response) item;
provideDescription(response, description);
}
};
}
示例8: informational
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
public static Matcher<Response> informational() {
return new CustomMatcher<Response>("1xx (informational) family of responses") {
@Override
public boolean matches(Object o) {
return (o instanceof Response)
&& (((Response) o).getStatusInfo().getFamily() == Response.Status.Family.INFORMATIONAL);
}
@Override
public void describeMismatch(Object item, Description description) {
Response response = (Response) item;
provideDescription(response, description);
}
};
}
示例9: other
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
public static Matcher<Response> other() {
return new CustomMatcher<Response>("unrecognized family of responses") {
@Override
public boolean matches(Object o) {
return (o instanceof Response)
&& (((Response) o).getStatusInfo().getFamily() == Response.Status.Family.OTHER);
}
@Override
public void describeMismatch(Object item, Description description) {
Response response = (Response) item;
provideDescription(response, description);
}
};
}
示例10: noContent
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
public static Matcher<Response> noContent() {
final int statusCode = Response.Status.NO_CONTENT.getStatusCode();
return new CustomMatcher<Response>("no content (" + statusCode + ")") {
@Override
public boolean matches(Object o) {
return (o instanceof Response)
&& (((Response) o).getStatus() == statusCode);
}
@Override
public void describeMismatch(Object item, Description description) {
Response response = (Response) item;
provideDescription(response, description);
}
};
}
示例11: serverError
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
public static Matcher<Response> serverError() {
final int statusCode = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
return new CustomMatcher<Response>("Internal server error(" + statusCode + ")") {
@Override
public boolean matches(Object o) {
return (o instanceof Response)
&& (((Response) o).getStatus() == statusCode);
}
@Override
public void describeMismatch(Object item, Description description) {
Response response = (Response) item;
provideDescription(response, description);
}
};
}
示例12: getAppliedMigrations_shouldQueryAndSortByName
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
@Test
public void getAppliedMigrations_shouldQueryAndSortByName() throws Exception {
ResultSet appliedMigrationResultSet = mock(ResultSet.class);
Row row = mock(Row.class);
when(session.execute(argThat(new CustomMatcher<Insert>("Get applied migrations") {
@Override
public boolean matches(Object item) {
return "SELECT name,status FROM test.migrations;".equals(item.toString());
}
}))).thenReturn(appliedMigrationResultSet);
when(appliedMigrationResultSet.all()).thenReturn(Collections.singletonList(row));
when(row.getString(0)).thenReturn("001_initial_migration.cql");
when(row.getString(1)).thenReturn("APPLIED");
assertThat(client.getAppliedMigrations()).containsOnly("001_initial_migration.cql");
}
示例13: getAppliedMigrations_shouldIgnoreFailedAndIncompleteMigrations
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
@Test
public void getAppliedMigrations_shouldIgnoreFailedAndIncompleteMigrations() throws Exception {
ResultSet appliedMigrationResultSet = mock(ResultSet.class);
Row row1 = mock(Row.class);
Row row2 = mock(Row.class);
when(session.execute(argThat(new CustomMatcher<Insert>("Get applied migrations") {
@Override
public boolean matches(Object item) {
return "SELECT name,status FROM test.migrations;".equals(item.toString());
}
}))).thenReturn(appliedMigrationResultSet);
when(appliedMigrationResultSet.all()).thenReturn(Arrays.asList(row1, row2));
when(row1.getString(0)).thenReturn("001_initial_migration.cql");
when(row1.getString(1)).thenReturn("APPLIED");
when(row2.getString(0)).thenReturn("002_add_stuff.cql");
when(row2.getString(1)).thenReturn("FAILED");
assertThat(client.getAppliedMigrations()).containsOnly("001_initial_migration.cql");
}
示例14: customMatcherShouldBeMoreCompact
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
@Test
public void customMatcherShouldBeMoreCompact() {
//when
int numberOfShips = ts.findNumberOfShipsInRangeByCriteria(searchCriteria);
//then
assertThat(numberOfShips).isZero();
//and
verify(ts).findNumberOfShipsInRangeByCriteria(argThat(new HamcrestArgumentMatcher<>(
new CustomMatcher<ShipSearchCriteria>("ShipSearchCriteria minimumRange<2000 and numberOfPhasers>2") {
@Override
public boolean matches(Object item) {
ShipSearchCriteria criteria = (ShipSearchCriteria) item;
return criteria.getMinimumRange() < 2000 && criteria.getNumberOfPhasers() > 2;
}
})));
}
示例15: testGetToken
import org.hamcrest.CustomMatcher; //导入依赖的package包/类
@Test
public void testGetToken() throws Exception {
User user = UserServiceTest.newInstence();
us.save(user);
mockMvc
.perform(
post("/api/token").param("email", user.getEmail()).param("password", user.getPassword())
.accept(MediaType.parseMediaType("application/json;charset=UTF-8"))).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.parseMediaType("application/json;charset=UTF-8")))
.andExpect(jsonPath("$.token").value(
// 匿名内部类,自定义Matcher,判断返回的json文的token属性是否是32个字符长的md5密文
new CustomMatcher<String>("长度为32的字符串") {
public boolean matches(Object object) {
return ((object instanceof String) && !((String) object).isEmpty() && ((String) object)
.length() == 32);
}
}));
}