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

The following examples show how to use org.hamcrest.Description#appendText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaMatchers.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * 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");
        }

    };
}
 
Example 2
Source File: HelpTest.java    From go-bees with GNU General Public License v3.0 6 votes vote down vote up
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));
        }
    };
}
 
Example 3
Source File: SWTBotCustomChartUtils.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
private static Matcher<Button> closeButtonForChart(final Chart chart) {
    return new AbstractMatcher<Button>() {

        @Override
        protected boolean doMatch(Object item) {
            if (!(item instanceof Button)) {
                return false;
            }
            Button button = (Button) item;
            return (button.getParent() == chart);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("delete button for custom chart");
        }
    };
}
 
Example 4
Source File: SnippetMatchers.java    From restdocs-wiremock with Apache License 2.0 5 votes vote down vote up
@Override
public void describeTo(Description description) {
	if (this.expectedContents != null) {
		this.expectedContents.describeTo(description);
	}
	else {
		description
				.appendText(this.templateFormat.getFileExtension() + " snippet");
	}
}
 
Example 5
Source File: JdkExtendedBooleanValueReaderReaderTest.java    From elasticsearch-hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public Matcher<Object> isNull() {
    return new BaseMatcher<Object>() {
        @Override
        public boolean matches(Object item) {
            return item == null;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("is null");
        }
    };
}
 
Example 6
Source File: MappingActionJsonMatcher.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Matches the contents of a native forward mapping action.
 *
 * @param node        JSON action to match
 * @param description object used for recording errors
 * @return true if the contents match, false otherwise
 */
private boolean matchNativeForwardAction(JsonNode node, Description description) {
    NativeForwardMappingAction actionToMatch = (NativeForwardMappingAction) action;
    final String jsonType = node.get(MappingActionCodec.TYPE).textValue();
    if (!actionToMatch.type().name().equals(jsonType)) {
        description.appendText("type was " + jsonType);
        return false;
    }
    return true;
}
 
Example 7
Source File: Helper.java    From android-nmea-parser with MIT License 5 votes vote down vote up
public static <T> ArgumentMatcher<List> eq(final List<T> expected) {
    return new ArgumentMatcher<List>() {
        @Override
        public boolean matches(Object argument) {
            return argument.equals(expected);
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(expected.toString());
        }
    };
}
 
Example 8
Source File: IgnoreFilePatternTest.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Override
public void describeMismatch(Object item, Description description) {
    description.appendText("was ");
    if (!(item instanceof IgnoreFilePattern.PathNameMatchResult)) {
        description.appendValue(item);
    } else {
        IgnoreFilePattern.PathNameMatchResult res = (IgnoreFilePattern.PathNameMatchResult) item;
        description.appendText("isMatch? ").appendValue(res.isMatch)
                .appendText(" requiresMore? ").appendValue(res.requiresMore)
                .appendText(" isLast? ").appendValue(res.isLastElementMatch)
                .appendText(" next ").appendValue(res.next);
    }
}
 
Example 9
Source File: FileContainsLines.java    From tool.accelerate.core with Apache License 2.0 5 votes vote down vote up
@Override
public void describeMismatch(Object file, Description description) {
    List<String> lines = readLinesSafely(file, description);
    if (lines != null) {
        lineMatchingDelegate.describeMismatch(lines, description);
        description.appendText(" in file ");
        description.appendValue(file);
        description.appendText(" with lines ");
        description.appendValue(readLinesSafely(file, Description.NONE));
    }
}
 
Example 10
Source File: TestUtils.java    From Scoops with Apache License 2.0 5 votes vote down vote up
public static Matcher<View> withTextColor(final int color) {
    Checks.checkNotNull(color);
    return new BoundedMatcher<View, TextView>(TextView.class) {
        @Override
        public boolean matchesSafely(TextView warning) {
            return color == warning.getCurrentTextColor();
        }
        @Override
        public void describeTo(Description description) {
            description.appendText("with text color: ");
        }
    };
}
 
Example 11
Source File: Same.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private void appendQuoting(Description description) {
    if (wanted instanceof String) {
        description.appendText("\"");
    } else if (wanted instanceof Character) {
        description.appendText("'");
    }
}
 
Example 12
Source File: BigqueryMatcher.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public void describeMismatchSafely(TableAndQuery tableAndQuery, Description description) {
  String info;
  if (!response.getJobComplete()) {
    // query job not complete
    info = String.format("The query job hasn't completed. Got response: %s", response);
  } else {
    // checksum mismatch
    info =
        String.format(
            "was (%s).%n" + "\tTotal number of rows are: %d.%n" + "\tQueried data details:%s",
            actualChecksum, response.getTotalRows(), formatRows(TOTAL_FORMATTED_ROWS));
  }
  description.appendText(info);
}
 
Example 13
Source File: MetricsSupport.java    From styx with Apache License 2.0 5 votes vote down vote up
@Override
public void describeTo(Description description) {
    StringBuilder sb = new StringBuilder();
    sb.append("not updated");

    if (excludedNames.size() > 0) {
        sb.append(" except {");
        sb.append(String.join(", ", excludedNames));
        sb.append("}");
    }

    description.appendText(sb.toString());
}
 
Example 14
Source File: BackPressureStatsTrackerImplITCase.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean matchesSafely(final OperatorBackPressureStats stats, final Description mismatchDescription) {
	if (!isBackPressureRatioCorrect(stats)) {
		mismatchDescription.appendText("Not all subtask back pressure ratios in " + getBackPressureRatios(stats) + " are " + expectedBackPressureRatio);
		return false;
	}
	return true;
}
 
Example 15
Source File: LispTeRecordJsonMatcher.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
public void describeTo(Description description) {
    description.appendText(record.toString());
}
 
Example 16
Source File: Assertions.java    From mattermost4j with Apache License 2.0 4 votes vote down vote up
/**
 * @see org.hamcrest.SelfDescribing#describeTo(org.hamcrest.Description)
 */
@Override
public void describeTo(Description description) {
  description.appendText("Should have failed");
}
 
Example 17
Source File: JsonDiffMatcher.java    From vividus with Apache License 2.0 4 votes vote down vote up
@Override
public void describeMismatch(Object item, Description mismatchDescription)
{
    String differences = super.getDifferences();
    mismatchDescription.appendText(null != differences ? differences : item.toString());
}
 
Example 18
Source File: RegionJsonMatcher.java    From onos with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean matchesSafely(JsonNode jsonRegion, Description description) {
    // check id
    String jsonRegionId = jsonRegion.get("id").asText();
    String regionId = region.id().toString();
    if (!jsonRegionId.equals(regionId)) {
        description.appendText("region id was " + jsonRegionId);
        return false;
    }

    // check type
    String jsonType = jsonRegion.get("type").asText();
    String type = region.type().toString();
    if (!jsonType.equals(type)) {
        description.appendText("type was " + jsonType);
        return false;
    }

    // check name
    String jsonName = jsonRegion.get("name").asText();
    String name = region.name();
    if (!jsonName.equals(name)) {
        description.appendText("name was " + jsonName);
        return false;
    }

    // check size of master array
    JsonNode jsonMasters = jsonRegion.get("masters");
    if (jsonMasters.size() != region.masters().size()) {
        description.appendText("masters size was " + jsonMasters.size());
        return false;
    }

    // check master
    for (Set<NodeId> set : region.masters()) {
        boolean masterFound = false;
        for (int masterIndex = 0; masterIndex < jsonMasters.size(); masterIndex++) {
            masterFound = checkEquality(jsonMasters.get(masterIndex), set);
        }

        if (!masterFound) {
            description.appendText("master not found " + set.toString());
            return false;
        }
    }

    return true;
}
 
Example 19
Source File: MapMatcher.java    From styx with Apache License 2.0 4 votes vote down vote up
@Override
protected void describeMismatchSafely(Map<K, V> actual, Description mismatchDescription) {
    mismatchDescription.appendText(String.valueOf(difference(actual, expected)));
}
 
Example 20
Source File: IsSameEvent.java    From Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud with MIT License 4 votes vote down vote up
@Override
public void describeTo(Description description) {
    String expectedJson = convertObjectToJsonString(expectedEvent);
    description.appendText("expected to look like " + expectedJson);
}