當前位置: 首頁>>代碼示例>>Java>>正文


Java StringDescription類代碼示例

本文整理匯總了Java中org.hamcrest.StringDescription的典型用法代碼示例。如果您正苦於以下問題:Java StringDescription類的具體用法?Java StringDescription怎麽用?Java StringDescription使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StringDescription類屬於org.hamcrest包,在下文中一共展示了StringDescription類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: assertThatClassIsImmutable

import org.hamcrest.StringDescription; //導入依賴的package包/類
/**
 * Assert that the given class adheres to the immutable class rules.
 *
 * @param clazz the class to check
 *
 * @throws java.lang.AssertionError if the class is not an
 *         immutable class
 */
public static void assertThatClassIsImmutable(Class<?> clazz) {
    final ImmutableClassChecker checker = new ImmutableClassChecker();
    if (!checker.isImmutableClass(clazz, false)) {
        final Description toDescription = new StringDescription();
        final Description mismatchDescription = new StringDescription();

        checker.describeTo(toDescription);
        checker.describeMismatch(mismatchDescription);
        final String reason =
                "\n" +
                "Expected: is \"" + toDescription.toString() + "\"\n" +
                "    but : was \"" + mismatchDescription.toString() + "\"";

        throw new AssertionError(reason);
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:25,代碼來源:ImmutableClassChecker.java

示例2: assertThatClassIsImmutableBaseClass

import org.hamcrest.StringDescription; //導入依賴的package包/類
/**
 * Assert that the given class adheres to the immutable class rules, but
 * is not declared final.  Classes that need to be inherited from cannot be
 * declared final.
 *
 * @param clazz the class to check
 *
 * @throws java.lang.AssertionError if the class is not an
 *         immutable class
 */
public static void assertThatClassIsImmutableBaseClass(Class<?> clazz) {
    final ImmutableClassChecker checker = new ImmutableClassChecker();
    if (!checker.isImmutableClass(clazz, true)) {
        final Description toDescription = new StringDescription();
        final Description mismatchDescription = new StringDescription();

        checker.describeTo(toDescription);
        checker.describeMismatch(mismatchDescription);
        final String reason =
                "\n" +
                        "Expected: is \"" + toDescription.toString() + "\"\n" +
                        "    but : was \"" + mismatchDescription.toString() + "\"";

        throw new AssertionError(reason);
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:27,代碼來源:ImmutableClassChecker.java

示例3: assertThatClassIsUtility

import org.hamcrest.StringDescription; //導入依賴的package包/類
/**
 * Assert that the given class adheres to the utility class rules.
 *
 * @param clazz the class to check
 *
 * @throws java.lang.AssertionError if the class is not a valid
 *         utility class
 */
public static void assertThatClassIsUtility(Class<?> clazz) {
    final UtilityClassChecker checker = new UtilityClassChecker();
    if (!checker.isProperlyDefinedUtilityClass(clazz)) {
        final Description toDescription = new StringDescription();
        final Description mismatchDescription = new StringDescription();

        checker.describeTo(toDescription);
        checker.describeMismatch(mismatchDescription);
        final String reason =
            "\n" +
            "Expected: is \"" + toDescription.toString() + "\"\n" +
            "    but : was \"" + mismatchDescription.toString() + "\"";

        throw new AssertionError(reason);
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:25,代碼來源:UtilityClassChecker.java

示例4: describeTo

import org.hamcrest.StringDescription; //導入依賴的package包/類
@Override
public void describeTo(Description description) {
	description.appendText("{\n");

	_entryMatchers.forEach(
		(key, matcher) -> {
			description.appendText("  ");
			description.appendText(key);
			description.appendText(": ");

			Description innerDescription = new StringDescription();

			matcher.describeTo(innerDescription);

			indentDescription(description, innerDescription);
		});

	description.appendText("}");
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:20,代碼來源:IsJsonObject.java

示例5: testInvokingDescribesToUpdatesDescription

import org.hamcrest.StringDescription; //導入依賴的package包/類
@Test
public void testInvokingDescribesToUpdatesDescription() {
	Conditions.Builder builder = new Conditions.Builder();

	Conditions conditions = builder.where(
		"apio", is(aJsonString(equalTo("Live long and prosper")))
	).where(
		"geek", is(aJsonBoolean(true))
	).build();

	Description description = new StringDescription();

	conditions.describeTo(description);

	String expected =
		"a JSON object where {\n  apio: is a string element with a value " +
			"that is \"Live long and prosper\"\n  geek: is a boolean " +
				"element with a value that is <true>\n}";

	assertThat(description.toString(), is(expected));
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:22,代碼來源:ConditionsTest.java

示例6: testInvokingMatchesElementInSoftModeValidates

import org.hamcrest.StringDescription; //導入依賴的package包/類
@Test
public void testInvokingMatchesElementInSoftModeValidates() {
	Conditions.Builder builder = new Conditions.Builder();

	Conditions conditions = builder.where(
		"geek", is(aJsonBoolean(true))
	).where(
		"apio", is(aJsonString(equalTo("Live long and prosper")))
	).withStrictModeDeactivated(
	).build();

	Description description = new StringDescription();

	JsonObject jsonObject = new JsonObject();

	jsonObject.addProperty("geek", true);
	jsonObject.addProperty("number", 42);
	jsonObject.addProperty("other", "apio");
	jsonObject.addProperty("apio", "Live long and prosper");

	boolean matchesElement = conditions.matches(jsonObject);
	conditions.describeMismatch(jsonObject, description);

	assertThat(matchesElement, is(true));
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:26,代碼來源:ConditionsTest.java

示例7: testInvalidJsonObjectWithMultiConditionUpdatesDescription

import org.hamcrest.StringDescription; //導入依賴的package包/類
@Test
public void testInvalidJsonObjectWithMultiConditionUpdatesDescription() {
	Conditions conditions = _builder.where(
		"apio", is(aJsonString(equalTo("Live long and prosper")))
	).where(
		"geek", is(aJsonBoolean(true))
	).build();

	Matcher<String> stringMatcher = aJsonObjectStringWith(conditions);

	Description description = new StringDescription();

	stringMatcher.describeMismatch("{}", description);

	String expected =
		"was a JSON object {\n  apio: was null\n  geek: was null\n}";

	assertThat(description.toString(), is(expected));
}
 
開發者ID:liferay,項目名稱:com-liferay-apio-architect,代碼行數:20,代碼來源:IsJsonObjectStringMatcherTest.java

示例8: verifyThat

import org.hamcrest.StringDescription; //導入依賴的package包/類
public static <T> boolean verifyThat(String reason, T actual, Matcher<? super T> matcher) {
	boolean result = matcher.matches(actual);
	Description description = new StringDescription();
	description.appendText(reason).appendText("\nExpected: ").appendDescriptionOf(matcher)
			.appendText("\n     Actual: ");

	matcher.describeMismatch(actual, description);
	String msg = description.toString();
	if (msg.endsWith("Actual: ")) {
		msg = String.format(msg + "%s", actual);
	}
	msg = msg.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
	Reporter.log(msg, result ? MessageTypes.Pass : MessageTypes.Fail);

	return result;
}
 
開發者ID:qmetry,項目名稱:qaf,代碼行數:17,代碼來源:Validator.java

示例9: assertTokenStream

import org.hamcrest.StringDescription; //導入依賴的package包/類
/**
 * Matches that the given <code>TokenStream</code> produces the expected sequence of tokens. Fails if a token does
 * not match its respective matcher, or if the number of tokens in the token stream does not match the number of
 * given matchers.
 * 
 * @param stream
 *           the token stream.
 * @param expectedTokens
 *           the matchers for the expected tokens.
 */
@SafeVarargs
protected final void assertTokenStream(TokenStream stream, Matcher<TokenStream>... expectedTokens) throws Exception {
   final int expectedTokenCount = expectedTokens.length;
   int tokenCount = 0;
   while (stream.incrementToken()) {
      assertTrue("Too many tokens", tokenCount < expectedTokens.length);
      Matcher<TokenStream> tokenMatcher = expectedTokens[tokenCount];
      boolean matches = tokenMatcher.matches(stream);
      if (!matches) {
         Description description = new StringDescription();
         description.appendText("Unexpected token at position ").appendValue(tokenCount).appendText("\n");
         tokenMatcher.describeMismatch(stream, description);
         fail(description.toString());
      }
      tokenCount++;
   }
   assertEquals("Unexpected number of tokens", expectedTokenCount, tokenCount);
}
 
開發者ID:shopping24,項目名稱:solr-analyzers,代碼行數:29,代碼來源:AbstractTokenFilterTest.java

示例10: describeNestedMismatchesNoEllipsisBeforeFirstValue

import org.hamcrest.StringDescription; //導入依賴的package包/類
@Test
public void describeNestedMismatchesNoEllipsisBeforeFirstValue() throws Exception {
  Set<String> allKeys = new LinkedHashSet<>(asList("first", "second", "third"));
  StringDescription description = new StringDescription();
  Map<String, Consumer<Description>> mismatchedKeys =
      ImmutableMap.of("first", desc -> desc.appendText("mismatch!"));
  BiConsumer<String, Description> describeKey = (str, desc) -> desc.appendText(str);

  DescriptionUtils.describeNestedMismatches(allKeys, description, mismatchedKeys, describeKey);

  assertThat(description.toString(), is(
      "{\n"
          + "  first: mismatch!\n"
          + "  ...\n"
          + "}"
  ));
}
 
開發者ID:spotify,項目名稱:java-hamcrest,代碼行數:18,代碼來源:DescriptionUtilsTest.java

示例11: testOffset

import org.hamcrest.StringDescription; //導入依賴的package包/類
@Test
public void testOffset() throws Exception {
   Description description = mock(Description.class);
   when(description.appendText(anyString())).thenReturn(description);
   when(description.appendValue(anyInt())).thenReturn(description);

   Matcher<TokenStream> offsetsMatcher = test.offsets(0, 1);
   offsetsMatcher.describeTo(description);

   verify(description, times(1)).appendText("startOffset=");
   verify(description, times(1)).appendValue(0);
   verify(description, times(1)).appendText(",endOffset=");
   verify(description, times(1)).appendValue(1);

   // Not a real test, but good for coverage
   assertFalse(test.offsets(42, 4711).matches(stream));
   test.offsets(42, 4711).describeMismatch(stream, new StringDescription());
}
 
開發者ID:shopping24,項目名稱:solr-analyzers,代碼行數:19,代碼來源:AbstractTokenFilterTestTest.java

示例12: testDescriptionFormatting

import org.hamcrest.StringDescription; //導入依賴的package包/類
@Test
public void testDescriptionFormatting() throws Exception {

  final IsPojo<SomeClass> sut = pojo(SomeClass.class)
      .where("baz", is(pojo(SomeClass.class).where("foo", is(42))))
      .where("foo", is(42))
      .withProperty("bar", is("bar"));

  final StringDescription description = new StringDescription();
  sut.describeTo(description);

  assertThat(description.toString(), is(
      "SomeClass {\n"
      + "  baz(): is SomeClass {\n"
      + "    foo(): is <42>\n"
      + "  }\n"
      + "  foo(): is <42>\n"
      + "  getBar(): is \"bar\"\n"
      + "}"
  ));
}
 
開發者ID:spotify,項目名稱:java-hamcrest,代碼行數:22,代碼來源:IsPojoTest.java

示例13: testMismatchFormatting

import org.hamcrest.StringDescription; //導入依賴的package包/類
@Test
public void testMismatchFormatting() throws Exception {
  final IsPojo<SomeClass> sut = pojo(SomeClass.class)
      .where("baz", is(
          pojo(SomeClass.class)
              .where("foo", is(43))
      ))
      .where("foo", is(42))
      .withProperty("bar", is("bar"));

  final StringDescription description = new StringDescription();
  sut.describeMismatch(new SomeClass(), description);

  assertThat(description.toString(), is(
      "SomeClass {\n"
      + "  baz(): SomeClass {\n"
      + "    foo(): was <42>\n"
      + "  }\n"
      + "  ...\n"
      + "}"
  ));
}
 
開發者ID:spotify,項目名稱:java-hamcrest,代碼行數:23,代碼來源:IsPojoTest.java

示例14: describeNestMismatchesNoEllipsisBetweenConsecutiveMismatches

import org.hamcrest.StringDescription; //導入依賴的package包/類
@Test
public void describeNestMismatchesNoEllipsisBetweenConsecutiveMismatches() throws Exception {
  Set<String> allKeys = new LinkedHashSet<>(asList("first", "second", "third", "forth"));
  StringDescription description = new StringDescription();
  Map<String, Consumer<Description>> mismatchedKeys = ImmutableMap.of(
      "second", desc -> desc.appendText("mismatch!"),
      "third", desc -> desc.appendText("mismatch!"));
  BiConsumer<String, Description> describeKey = (str, desc) -> desc.appendText(str);

  DescriptionUtils.describeNestedMismatches(allKeys, description, mismatchedKeys, describeKey);

  assertThat(description.toString(), is(
      "{\n"
          + "  ...\n"
          + "  second: mismatch!\n"
          + "  third: mismatch!\n"
          + "  ...\n"
          + "}"
  ));
}
 
開發者ID:spotify,項目名稱:java-hamcrest,代碼行數:21,代碼來源:DescriptionUtilsTest.java

示例15: testTypeSafeMismatch

import org.hamcrest.StringDescription; //導入依賴的package包/類
@Test
public void testTypeSafeMismatch() throws Exception {
  final IsPojo<SomeClass> sut = pojo(SomeClass.class)
      .where(SomeClass::foo, is(41))
      .where(SomeClass::baz, is(
          pojo(SomeClass.class)
              .where(SomeClass::foo, is(43))
      ));

  final StringDescription description = new StringDescription();
  sut.describeMismatch(new SomeClass(), description);

  assertThat(description.toString(), is(
      "SomeClass {\n"
      + "  foo(): was <42>\n"
      + "  baz(): SomeClass {\n"
      + "    foo(): was <42>\n"
      + "  }\n"
      + "}"
  ));
}
 
開發者ID:spotify,項目名稱:java-hamcrest,代碼行數:22,代碼來源:IsPojoTest.java


注:本文中的org.hamcrest.StringDescription類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。