Java Code Examples for org.hamcrest.Description.appendText()

The following are Jave code examples for showing how to use appendText() of the org.hamcrest.Description class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: athena   File: MastershipTermCodecTest.java   View Source Code Vote up 6 votes
@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;
}
 
Example 2
Project: spring-spreadsheet   File: SpreadsheetsMatchers.java   View Source Code Vote up 6 votes
public static Matcher<byte[]> isActuallyAnExcelFile() {
    return new BaseMatcher<byte[]>() {
        @Override
        public boolean matches(Object o) {
            final List<String> names = new ArrayList<>();

            try (ZipInputStream zipStream = new ZipInputStream(new ByteArrayInputStream((byte[]) o))) {
                ZipEntry zipEntry;
                while ((zipEntry = zipStream.getNextEntry()) != null) {
                    names.add(zipEntry.getName());
                    zipStream.closeEntry();
                }
            } catch (IOException e) {
                return false;
            }

            return hasItems("_rels/.rels", "docProps/app.xml", "xl/styles.xml", "xl/workbook.xml").matches(names);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("Given binary data corresponds to an excel file");
        }
    };
}
 
Example 3
Project: generator-thundr-gae-react   File: Matchers.java   View Source Code Vote up 6 votes
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));
        }
    };
}
 
Example 4
Project: espresso-sample-for-droidkaigi2017   File: RecyclerViewUtils.java   View Source Code Vote up 6 votes
/**
 * <p>
 * Returns a matcher that matches an item view at the given position
 * in the RecyclerView matched by {@code recyclerViewMatcher}.
 * </p>
 * <p>
 * If the item view at the given position is not laid out,
 * the matcher returned by this method will not match anything.
 * Call {@link android.support.test.espresso.contrib.RecyclerViewActions#scrollToPosition(int)}
 * with the same position prior to calling this method
 * in order to ensure that the item view is laid out.
 * </p>
 * <pre><code>
 *     onView(withId(R.id.recyclerView).perform(RecyclerViewActions.scrollToPosition(position);
 * </code></pre>
 *
 * @param recyclerViewMatcher a matcher for RecyclerView containing the item view.
 * @param position            position of the item view in RecyclerView
 */
public static Matcher<View> withItemViewAtPosition(final Matcher<View> recyclerViewMatcher, final int position) {
    return new TypeSafeMatcher<View>() {
        @Override
        protected boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            if (!(parent instanceof RecyclerView) || !recyclerViewMatcher.matches(parent)) {
                return false;
            }
            RecyclerView.ViewHolder viewHolder = ((RecyclerView) parent).findViewHolderForAdapterPosition(position);
            return viewHolder != null && viewHolder.itemView.equals(view);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("Item view at position " + position + " in recycler view ");
            recyclerViewMatcher.describeTo(description);
        }
    };
}
 
Example 5
Project: athena   File: InstructionJsonMatcher.java   View Source Code Vote up 6 votes
/**
 * Matches the contents of a mod IPv6 Flow 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 matchModIPv6FlowLabelInstruction(JsonNode instructionJson,
                                                 Description description) {
    ModIPv6FlowLabelInstruction instructionToMatch =
            (ModIPv6FlowLabelInstruction) 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 jsonFlowLabel = instructionJson.get("flowLabel").intValue();
    final int flowLabel = instructionToMatch.flowLabel();
    if (flowLabel != jsonFlowLabel) {
        description.appendText("IPv6 flow label was " + jsonFlowLabel);
        return false;
    }

    return true;
}
 
Example 6
Project: mod-circulation-storage   File: TextDateTimeMatcher.java   View Source Code Vote up 6 votes
public static Matcher<String> withinSecondsAfter(Seconds seconds, DateTime after) {
    return new TypeSafeMatcher<String>() {
      @Override
      public void describeTo(Description description) {
        description.appendText(String.format(
          "a date time within %s seconds after %s",
          seconds.getSeconds(), after.toString()));
      }

      @Override
      protected boolean matchesSafely(String textRepresentation) {
        //response representation might vary from request representation
        DateTime actual = DateTime.parse(textRepresentation);

        return actual.isAfter(after) &&
          Seconds.secondsBetween(after, actual).isLessThan(seconds);
      }
    };
}
 
Example 7
Project: athena   File: ApplicationIdCodecTest.java   View Source Code Vote up 6 votes
@Override
protected boolean matchesSafely(JsonNode jsonNode, Description description) {

    // check application role
    int jsonAppId = jsonNode.get("id").asInt();
    int appId = applicationId.id();
    if (jsonAppId != appId) {
        description.appendText("application ID was " + jsonAppId);
        return false;
    }

    String jsonAppName = jsonNode.get("name").asText();
    String appName = applicationId.name();

    if (!jsonAppName.equals(appName)) {
        description.appendText("application name was " + jsonAppName);
        return false;
    }

    return true;
}
 
Example 8
Project: Guardian.java   File: RecordedRequestMatcher.java   View Source Code Vote up 6 votes
@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);
    }
}
 
Example 9
Project: java-memory-assistant   File: IncreaseOverTimeFrameThresholdConditionTest.java   View Source Code Vote up 5 votes
private static TypeSafeMatcher<IncreaseOverTimeFrameUsageThresholdCondition>
    hasMeasurementPeriodInMillis(final long millis) {
  return new TypeSafeMatcher<IncreaseOverTimeFrameUsageThresholdCondition>() {
    @Override
    protected boolean matchesSafely(
        IncreaseOverTimeFrameUsageThresholdCondition condition) {
      return millis == condition.measurementPeriod;
    }

    @Override
    public void describeTo(Description description) {
      description.appendText("has a measurement period of '" + millis + "' millis");
    }
  };
}
 
Example 10
Project: GitHub   File: ConnectbotMatchers.java   View Source Code Vote up 5 votes
@NonNull
public static Matcher<RecyclerView.ViewHolder> withDisconnectedHost() {
	return new BoundedMatcher<RecyclerView.ViewHolder, HostListActivity.HostViewHolder>(HostListActivity.HostViewHolder.class) {
		@Override
		public boolean matchesSafely(HostListActivity.HostViewHolder holder) {
			return hasDrawableState(holder.icon, android.R.attr.state_expanded);
		}

		@Override
		public void describeTo(Description description) {
			description.appendText("is disconnected status");
		}
	};
}
 
Example 11
Project: athena   File: MulticastRouteResourceTest.java   View Source Code Vote up 4 votes
@Override
public void describeTo(Description description) {
    description.appendText(reason);
}
 
Example 12
Project: Reer   File: ReflectionEqualsMatcher.java   View Source Code Vote up 4 votes
public void describeTo(Description description) {
    description.appendText("an Object with the same fields as " + toMatch);
}
 
Example 13
Project: athena   File: TenantWebResourceTest.java   View Source Code Vote up 4 votes
@Override
public void describeTo(Description description) {
    description.appendText(reason);
}
 
Example 14
Project: incubator-servicecomb-saga   File: SagaEventMatcher.java   View Source Code Vote up 4 votes
@Override
public void describeTo(Description description) {
  description
      .appendText("SagaEvent {sagaId=" + sagaId + ", operation=" + operation + ", class=" + aClass.getCanonicalName());
}
 
Example 15
Project: com-liferay-apio-architect   File: SuccessTry.java   View Source Code Vote up 4 votes
@Override
public void describeTo(final Description description) {
	description.appendText("a Success");
}
 
Example 16
Project: com-liferay-apio-architect   File: IsAFunctionalList.java   View Source Code Vote up 4 votes
@Override
protected boolean matchesSafely(
	final FunctionalList<E> functionalList, final Description description) {

	E head = functionalList.head();

	Stream<E> stream = Stream.concat(
		Stream.of(head), functionalList.tailStream());

	List<E> list = stream.collect(Collectors.toList());

	if (_matcher.matches(list)) {
		return true;
	}

	description.appendText("was a functional list whose ");

	_matcher.describeMismatch(list, description);

	return false;
}
 
Example 17
Project: pact-spring-mvc   File: JsonSchemaMatcher.java   View Source Code Vote up 4 votes
@Override
public void describeTo(Description description) {
    description.appendText("matches a json schema of " + unparsedSchema);
}
 
Example 18
Project: athena   File: GroupsResourceTest.java   View Source Code Vote up 4 votes
@Override
public void describeTo(Description description) {
    description.appendText(reason);
}
 
Example 19
Project: athena   File: ImmutableClassChecker.java   View Source Code Vote up 2 votes
/**
 * Describe why an error was reported.  Uses Hamcrest style Description
 * interfaces.
 *
 * @param description the Description object to use for reporting the
 *                    mismatch
 */
public void describeMismatch(Description description) {
    description.appendText(failureReason);
}
 
Example 20
Project: athena   File: ImmutableClassChecker.java   View Source Code Vote up 2 votes
/**
 * Describe the source object that caused an error, using a Hamcrest
 * Matcher style interface.  In this case, it always returns
 * that we are looking for a properly defined utility class.
 *
 * @param description the Description object to use to report the "to"
 *                    object
 */
public void describeTo(Description description) {
    description.appendText("a properly defined immutable class");
}