本文整理匯總了Java中org.hamcrest.Description類的典型用法代碼示例。如果您正苦於以下問題:Java Description類的具體用法?Java Description怎麽用?Java Description使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Description類屬於org.hamcrest包,在下文中一共展示了Description類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: childAtPosition
import org.hamcrest.Description; //導入依賴的package包/類
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
示例2: hasFieldWithUserRef
import org.hamcrest.Description; //導入依賴的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: matchesSafely
import org.hamcrest.Description; //導入依賴的package包/類
@Override
protected boolean matchesSafely(RecordedRequest item, Description mismatchDescription) {
if (item == null) {
mismatchDescription.appendText("was null");
return false;
}
switch (checkingOption) {
default:
case METHOD_PATH:
return matchesMethodAndPath(item, mismatchDescription);
case HEADER:
return matchesHeader(item, mismatchDescription);
case QUERY_PARAMETER:
return matchesQueryParameter(item, mismatchDescription);
}
}
示例4: getGraph
import org.hamcrest.Description; //導入依賴的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;
}
示例5: withIndex
import org.hamcrest.Description; //導入依賴的package包/類
public static Matcher<View> withIndex(final Matcher<View> matcher, final int index) {
return new TypeSafeMatcher<View>() {
int currentIndex = 0;
@Override
public void describeTo(Description description) {
description.appendText("with index: ");
description.appendValue(index);
matcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
return matcher.matches(view) && currentIndex++ == index;
}
};
}
示例6: childAtPosition
import org.hamcrest.Description; //導入依賴的package包/類
public static org.hamcrest.Matcher<View> childAtPosition(
final org.hamcrest.Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
示例7: matchesSafely
import org.hamcrest.Description; //導入依賴的package包/類
@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {
// check node identifier of master
String jsonNodeId = jsonNode.get("master").asText();
String nodeId = mastershipTerm.master().id();
if (!jsonNodeId.equals(nodeId)) {
description.appendText("master's node id was " + jsonNodeId);
return false;
}
// check term number
long jsonTermNumber = jsonNode.get("termNumber").asLong();
long termNumber = mastershipTerm.termNumber();
if (jsonTermNumber != termNumber) {
description.appendText("term number was " + jsonTermNumber);
return false;
}
return true;
}
示例8: hasItems
import org.hamcrest.Description; //導入依賴的package包/類
/**
* Checks if collection has the given number of items.
*/
public static Matcher<Collection<?>> hasItems(final int numberOfItems) {
return new TypeSafeMatcher<Collection<?>>() {
@Override
public boolean matchesSafely(Collection<?> collection) {
if (collection == null || collection.size() != numberOfItems) {
return false;
}
return true;
}
@Override
public void describeTo(Description description) {
description.appendText("expected a collection with "
+ numberOfItems + " items");
}
};
}
示例9: matchModVlanPcpInstruction
import org.hamcrest.Description; //導入依賴的package包/類
/**
* Matches the contents of a mod vlan pcp instruction.
*
* @param instructionJson JSON instruction to match
* @param description Description object used for recording errors
* @return true if contents match, false otherwise
*/
private boolean matchModVlanPcpInstruction(JsonNode instructionJson,
Description description) {
ModVlanPcpInstruction instructionToMatch =
(ModVlanPcpInstruction) instruction;
final String jsonSubtype = instructionJson.get("subtype").textValue();
if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
description.appendText("subtype was " + jsonSubtype);
return false;
}
final String jsonType = instructionJson.get("type").textValue();
if (!instructionToMatch.type().name().equals(jsonType)) {
description.appendText("type was " + jsonType);
return false;
}
final short jsonVlanPcp = instructionJson.get("vlanPcp").shortValue();
final short vlanId = instructionToMatch.vlanPcp();
if (jsonVlanPcp != vlanId) {
description.appendText("vlan pcp was " + jsonVlanPcp);
return false;
}
return true;
}
示例10: matchModMplsLabelInstruction
import org.hamcrest.Description; //導入依賴的package包/類
/**
* Matches the contents of a mod MPLS label instruction.
*
* @param instructionJson JSON instruction to match
* @param description Description object used for recording errors
* @return true if contents match, false otherwise
*/
private boolean matchModMplsLabelInstruction(JsonNode instructionJson,
Description description) {
ModMplsLabelInstruction instructionToMatch =
(ModMplsLabelInstruction) instruction;
final String jsonSubtype = instructionJson.get("subtype").textValue();
if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
description.appendText("subtype was " + jsonSubtype);
return false;
}
final String jsonType = instructionJson.get("type").textValue();
if (!instructionToMatch.type().name().equals(jsonType)) {
description.appendText("type was " + jsonType);
return false;
}
final int jsonLabel = instructionJson.get("label").intValue();
final int label = instructionToMatch.label().toInt();
if (label != jsonLabel) {
description.appendText("MPLS label was " + jsonLabel);
return false;
}
return true;
}
示例11: equalsVideoDataInCursor
import org.hamcrest.Description; //導入依賴的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);
}
};
}
示例12: isSameAs
import org.hamcrest.Description; //導入依賴的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);
}
};
}
示例13: matchesQueryParameter
import org.hamcrest.Description; //導入依賴的package包/類
private boolean matchesQueryParameter(RecordedRequest item, Description mismatchDescription) {
String path = item.getPath();
boolean hasQuery = path.indexOf("?") > 0;
if (!hasQuery) {
mismatchDescription.appendText(" query was empty");
return false;
}
String query = path.substring(path.indexOf("?") + 1, path.length());
String[] parameters = query.split("&");
for (String p : parameters) {
if (p.equals(String.format("%s=%s", first, second))) {
return true;
}
}
mismatchDescription.appendValueList("Query parameters were {", ", ", "}.", parameters);
return false;
}
示例14: describeMismatchSafely
import org.hamcrest.Description; //導入依賴的package包/類
@Override
public void describeMismatchSafely(
final MimeType item,
final Description desc
) {
try {
desc.appendText("was param ")
.appendDescriptionOf(
new ParamDescription(
this.name,
item.params().get(this.name)
)
);
} catch (final IOException err) {
desc.appendText("was not set");
}
}
示例15: hasItemInArray
import org.hamcrest.Description; //導入依賴的package包/類
/**
* Checks if array is non-empty. This matcher can be replaced with JUnit 4.8
*/
public static Matcher<Object[]> hasItemInArray() {
return new TypeSafeMatcher<Object[]>() {
@Override
public boolean matchesSafely(Object[] arrayToTest) {
if (arrayToTest == null || arrayToTest.length == 0) {
return false;
}
return true;
}
@Override
public void describeTo(Description description) {
description.appendText("non-empty array");
}
};
}