本文整理汇总了Java中org.hamcrest.BaseMatcher类的典型用法代码示例。如果您正苦于以下问题:Java BaseMatcher类的具体用法?Java BaseMatcher怎么用?Java BaseMatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BaseMatcher类属于org.hamcrest包,在下文中一共展示了BaseMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
@Before
public void init() {
audienceManagerService = mock(AudienceManagerService.class);
authenticationManager = mock(AuthenticationManager.class);
UserDetailsService userDetailsService = mock(UserDetailsService.class);
TokenBasedRememberMeServices rememberMeServices = spy(new TokenBasedRememberMeServices("key", userDetailsService));
provider = new AudienceManagerSecurityProvider(audienceManagerService, authenticationManager, rememberMeServices);
token.setDetails("id");
doThrow(new BadCredentialsException("Test")).when(authenticationManager).authenticate(any(Authentication.class));
doReturn(token).when(authenticationManager).authenticate(argThat(new BaseMatcher<Authentication>() {
@Override
public boolean matches(Object item) {
return ((Authentication) item).getPrincipal().equals("user");
}
@Override
public void describeTo(Description description) {
description.appendText("Username is user");
}
}));
}
示例2: hasFieldWithUserRef
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static <T> Matcher<T> hasFieldWithUserRef(final String fieldName, final User user) {
return new BaseMatcher<T>() {
@Override
public boolean matches(Object o) {
Ref<User> userRef = TestSupport.getField(o, fieldName);
if (user == null) {
return userRef == null;
} else {
String username = userRef.getKey().getName();
return user.getUsername().equals(username);
}
}
@Override
public void describeTo(Description description) {
description.appendText(String.format("User with username '%s' on field %s", user, fieldName));
}
};
}
示例3: containsLine
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
@Factory
@Deprecated
/**
* Please avoid using as the hamcrest way of reporting error wraps a multi-line
* text into a single line and makes hard to understand the problem.
* Instead, please try to use the spock/groovy assert and {@link #containsLine(String, String)}
*/
public static Matcher<String> containsLine(final String line) {
return new BaseMatcher<String>() {
public boolean matches(Object o) {
return containsLine(equalTo(line)).matches(o);
}
public void describeTo(Description description) {
description.appendText("a String that contains line ").appendValue(line);
}
};
}
示例4: isSerializable
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
@Factory
public static Matcher<Object> isSerializable() {
return new BaseMatcher<Object>() {
public boolean matches(Object o) {
try {
new ObjectOutputStream(new ByteArrayOutputStream()).writeObject(o);
} catch (IOException e) {
throw new RuntimeException(e);
}
return true;
}
public void describeTo(Description description) {
description.appendText("is serializable");
}
};
}
示例5: getMatcher
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
private BaseMatcher<BindException> getMatcher(String message, String field) {
return new BaseMatcher<BindException>() {
@Override
public void describeTo(Description description) {
}
@Override
public boolean matches(Object item) {
BindException ex = (BindException) ((Exception) item).getCause();
ObjectError error = ex.getAllErrors().get(0);
boolean messageMatches = message.equals(error.getDefaultMessage());
if (field == null) {
return messageMatches;
}
String fieldErrors = ((FieldError) error).getField();
return messageMatches && fieldErrors.equals(field);
}
};
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:23,代码来源:ResourceServerPropertiesTests.java
示例6: within
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
private static Matcher within(double epsilon, double value) {
return new BaseMatcher() {
@Override
public void describeTo(Description description) {
description.appendText("within ")
.appendText(Double.toString(epsilon))
.appendText(" of ")
.appendText(Double.toString(value));
}
@Override
public boolean matches(Object item) {
return item instanceof Double && Math.abs(((Double)item) - value) < epsilon;
}
};
}
示例7: isSameAs
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static Matcher<List<AuditLogEntry>> isSameAs(
final List<AuditLog> auditLogs) {
return new BaseMatcher<List<AuditLogEntry>>() {
private int errorPosition;
@Override
public boolean matches(Object object) {
List<AuditLogEntry> auditLogEntries = (List<AuditLogEntry>) object;
assertEquals(auditLogEntries.size(), auditLogs.size());
for (int i = 0; i < auditLogEntries.size(); i++) {
errorPosition = i;
compareAuditLogEntry(auditLogEntries.get(i),
auditLogs.get(i));
}
return true;
}
@Override
public void describeTo(Description description) {
description
.appendText("AuditLogEntry is not equal with AuditLog at position "
+ errorPosition);
}
};
}
示例8: sortedCreationTimes
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static Matcher<List<AuditLog>> sortedCreationTimes() {
return new BaseMatcher<List<AuditLog>>() {
@Override
public boolean matches(Object object) {
List<AuditLog> auditLogs = (List<AuditLog>) object;
for (int i = 0; i < auditLogs.size()-1; i++) {
assertTrue(auditLogs.get(i).getCreationTime()<=auditLogs.get(i+1).getCreationTime());
}
return true;
}
@Override
public void describeTo(Description description) {
description
.appendText("AuditLogEntry List not sorted on creation time.");
}
};
}
示例9: notSortedCreationTimes
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static Matcher<List<AuditLog>> notSortedCreationTimes() {
return new BaseMatcher<List<AuditLog>>() {
@Override
public boolean matches(Object object) {
List<AuditLog> auditLogs = (List<AuditLog>) object;
for (int i = 0; i < auditLogs.size()-1; i++) {
if (auditLogs.get(i).getCreationTime()>auditLogs.get(i+1).getCreationTime()) {
return true;
}
}
return false;
}
@Override
public void describeTo(Description description) {
description
.appendText("AuditLogEntry List sorted on creation time.");
}
};
}
示例10: isCorrectTimeStampFormat
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static Matcher<String> isCorrectTimeStampFormat() {
return new BaseMatcher<String>() {
@Override
public boolean matches(Object object) {
String string = (String) object;
assertTrue(string
.matches("[0-9]{2,}/[0-9]{2,}/[0-9]{4,}_[0-9]{2,}:[0-9]{2,}:[0-9]{2,}\\.[0-9]{3,}"));
return true;
}
@Override
public void describeTo(Description description) {
description
.appendText("Timestamp format is wrong. MM/dd/YYYY_hh:mm:ss.SSS expected");
}
};
}
示例11: hasContent
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static Matcher<? super HttpResponse> hasContent(final String content, final String charset) {
return new BaseMatcher<HttpResponse>() {
public boolean matches(Object o) {
try {
HttpResponse response = (HttpResponse) o;
Reader reader = new InputStreamReader(response.getEntity().getContent(), charset);
int intValueOfChar;
String targetString = "";
while ((intValueOfChar = reader.read()) != -1) {
targetString += (char) intValueOfChar;
}
reader.close();
return targetString.equals(content);
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public void describeTo(Description description) {
description.appendText(content);
}
};
}
示例12: getGraph
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
/**
* @return the graph
*/
public GWGraph getGraph() {
if (graph==null) {
List<SWTBotGefEditPart> parts = editor.editParts(new BaseMatcher<EditPart>() {
@Override
public boolean matches(Object item) {
if (item instanceof org.gw4e.eclipse.studio.part.editor.GraphPart) return true;
if (item instanceof org.gw4e.eclipse.studio.part.editor.VertexPart) return true;
if (item instanceof org.gw4e.eclipse.studio.part.editor.EdgePart) return true;
return false;
}
@Override
public void describeTo(Description description) {
}
});
if (parts==null || parts.size() ==0) {
throw new RuntimeException("Empty Graph");
}
graph = getGraph (parts.get(0));
}
return graph;
}
示例13: equalToMensas
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
private Matcher<List<Mensa>> equalToMensas(List<Mensa> mensas) {
return new BaseMatcher<List<Mensa>>() {
@Override
@SuppressWarnings("unchecked")
public boolean matches(Object item) {
List<Mensa> matchTargetList = (List<Mensa>) item;
if (matchTargetList.size() != mensas.size()) {
return false;
} else {
for (int i = 0; i < mensas.size(); i++) {
Mensa mensa = mensas.get(i);
Mensa matchTarget = matchTargetList.get(i);
if (!EqualsBuilder.reflectionEquals(mensa, matchTarget, Arrays.asList("updatedAt"))) {
return false;
}
}
return true;
}
}
@Override
public void describeTo(Description description) {
description.appendText("each mensa should be equal except for the update value");
}
};
}
示例14: captureCreatedRadiator
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
public static BaseMatcher<String> captureCreatedRadiator(CreatedRadiator createdRadiator) {
return new BaseMatcher<String>() {
@Override
public boolean matches(Object o) {
try {
CreatedRadiator cr = new ObjectMapper().readValue((String) o, CreatedRadiator.class);
createdRadiator.code = cr.code;
createdRadiator.secret = cr.secret;
} catch (IOException e) {
fail("IOE encountered " + e.getMessage());
}
return true;
}
@Override
public void describeTo(Description description) {
}
};
}
示例15: equalsVideoDataInCursor
import org.hamcrest.BaseMatcher; //导入依赖的package包/类
/**
* Checks that the given {@code VideoLibraryModel.Video} is equal to the video data in the given
* cursor table at the given {@code index}.
*/
private Matcher<VideoLibraryModel.Video> equalsVideoDataInCursor(final Object[][] cursorTable,
final int index) {
return new BaseMatcher<VideoLibraryModel.Video>() {
@Override
public boolean matches(final Object item) {
final VideoLibraryModel.Video video = (VideoLibraryModel.Video) item;
return video.getId().equals(cursorTable[VIDEO_ID_COLUMN_INDEX][index])
&& video.getYear() == (Integer) cursorTable[VIDEO_YEAR_COLUMN_INDEX][index]
&& video.getTopic().equals(cursorTable[VIDEO_TOPIC_COLUMN_INDEX][index])
&& video.getTitle().equals(cursorTable[VIDEO_TITLE_COLUMN_INDEX][index])
&& video.getDesc().equals(cursorTable[VIDEO_DESC_COLUMN_INDEX][index])
&& video.getVid().equals(cursorTable[VIDEO_VID_COLUMN_INDEX][index])
&& video.getSpeakers().equals(
cursorTable[VIDEO_SPEAKER_COLUMN_INDEX][index])
&& video.getThumbnailUrl().equals(
cursorTable[VIDEO_THUMBNAIL_URL_COLUMN_INDEX][index]);
}
@Override
public void describeTo(final Description description) {
description.appendText("The Video does not match the data in table ")
.appendValue(cursorTable).appendText(" at index ").appendValue(index);
}
};
}