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


Java TypeSafeDiagnosingMatcher類代碼示例

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


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

示例1: everyItemInArray

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
private static <T> Matcher<T[]> everyItemInArray(final Matcher<T> itemMatcher) {
    return new TypeSafeDiagnosingMatcher<T[]>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("every item in array is ").appendDescriptionOf(itemMatcher);
        }

        @Override
        protected boolean matchesSafely(T[] items, Description mismatchDescription) {
            for (T item : items) {
                if (!itemMatcher.matches(item)) {
                    mismatchDescription.appendText("an item ");
                    itemMatcher.describeMismatch(item, mismatchDescription);
                    return false;
                }
            }
            return true;
        }

    };
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:IncludeAccessorsPropertiesIT.java

示例2: successfulExitCode

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
private TypeSafeDiagnosingMatcher<Integer> successfulExitCode(
    final Command cmd, final File workspace) {
  return new TypeSafeDiagnosingMatcher<Integer>() {
    @Override
    protected boolean matchesSafely(
        final Integer exitCode, final Description mismatchDescription) {
      if (exitCode != 0) {
        mismatchDescription
            .appendText(" exit code was ")
            .appendValue(exitCode)
            .appendText("\n")
            .appendText("Workspace contents: \n")
            .appendValueList("", "\n", "\n", contents(workspace.toPath()))
            .appendDescriptionOf(commandDescription(cmd));
        return false;
      }
      return true;
    }

    @Override
    public void describeTo(final Description description) {
      description.appendText("successful exit code (0)");
    }
  };
}
 
開發者ID:bazelbuild,項目名稱:bazel-integration-testing,代碼行數:26,代碼來源:BazelBaseTestCaseTest.java

示例3: validationError

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
public static Matcher<ValidationError> validationError(final String propertyPath, final String message) {
    return new TypeSafeDiagnosingMatcher<ValidationError>() {
        @Override
        protected boolean matchesSafely(ValidationError item, Description mismatchDescription) {
            if (!item.getErrorMessage().equals(message)) {
                mismatchDescription.appendText("message was " + item.getErrorMessage());
                return false;
            }

            if (!item.getFieldPath().equals(propertyPath)) {
                mismatchDescription.appendText("field path was " + item.getFieldPath());
                return false;
            }

            return true;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("a validation error for field " + propertyPath + " with message " + message);
        }
    };
}
 
開發者ID:energizedwork,項目名稱:swagger-http-validator,代碼行數:24,代碼來源:CustomMatchers.java

示例4: matchingPattern

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
public static Matcher<String> matchingPattern(String patternStr) {
    return new TypeSafeDiagnosingMatcher<String>() {
        @Override
        protected boolean matchesSafely(String text, Description mismatchDescription) {
            Pattern pattern = Pattern.compile(patternStr, Pattern.DOTALL);
            boolean matches = pattern.matcher(text).matches();
            if (!matches) {
                mismatchDescription.appendText(text);
            }
            return matches;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("matching '" + patternStr + "'");
        }
    };
}
 
開發者ID:palantir,項目名稱:docker-compose-rule,代碼行數:19,代碼來源:IOMatchers.java

示例5: hasTag

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
public static Matcher<Git> hasTag(final String tag) {
	return new TypeSafeDiagnosingMatcher<Git>() {
		@Override
		protected boolean matchesSafely(final Git repo, final Description mismatchDescription) {
			try {
				mismatchDescription.appendValueList("a git repo with tags: ", ", ", "",
						repo.getRepository().getTags().keySet());
				for (final Ref ref : repo.tagList().call()) {
					final String currentTag = ref.getName().replace(REFS_TAGS, "");
					if (tag.equals(currentTag)) {
						return true;
					}
				}
				return false;
			} catch (final GitAPIException e) {
				throw new RuntimeException("Couldn't access repo", e);
			}
		}

		@Override
		public void describeTo(final Description description) {
			description.appendText("a git repo with the tag " + tag);
		}
	};
}
 
開發者ID:SourcePond,項目名稱:release-maven-plugin-parent,代碼行數:26,代碼來源:GitMatchers.java

示例6: hasCleanWorkingDirectory

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
public static Matcher<Git> hasCleanWorkingDirectory() {
	return new TypeSafeDiagnosingMatcher<Git>() {
		@Override
		protected boolean matchesSafely(final Git git, final Description mismatchDescription) {
			try {
				final Status status = git.status().call();
				if (!status.isClean()) {
					final String start = "Uncommitted changes in ";
					final String end = " at " + git.getRepository().getWorkTree().getAbsolutePath();
					mismatchDescription.appendValueList(start, ", ", end, status.getUncommittedChanges());
				}
				return status.isClean();
			} catch (final GitAPIException e) {
				throw new RuntimeException("Error checking git status", e);
			}
		}

		@Override
		public void describeTo(final Description description) {
			description.appendText("A git directory with no staged or unstaged changes");
		}
	};
}
 
開發者ID:SourcePond,項目名稱:release-maven-plugin-parent,代碼行數:24,代碼來源:GitMatchers.java

示例7: isSuccess

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
protected Matcher<CompilationResult> isSuccess() {
    return new TypeSafeDiagnosingMatcher<CompilationResult>() {
        @Override public void describeTo(final Description description) {
            description.appendText("Successful compilation");
        }

        @Override protected boolean matchesSafely(final CompilationResult item,
                                                  final Description mismatchDescription) {
            final boolean success = item.isSuccess();
            if (!success) mismatchDescription.appendText(Joiner.on('\n').join(item.getErrors()));
            return success;
        }

        ;
    };

}
 
開發者ID:mostlymagic,項目名稱:hacking-java,代碼行數:18,代碼來源:AbstractCompilerTest.java

示例8: isFailureWithExpectedMessage

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
protected Matcher<CompilationResult> isFailureWithExpectedMessage(String message) {
    return new TypeSafeDiagnosingMatcher<CompilationResult>() {
        @Override public void describeTo(final Description description) {
            description.appendText("Compilation Failure");
        }

        @Override protected boolean matchesSafely(final CompilationResult item,
                                                  final Description mismatchDescription) {
            boolean falseSuccess = item.isSuccess();
            final String errorMessagesAsBlock = Joiner.on('\n').join(item.getErrors());
            if (!errorMessagesAsBlock.contains(message)) {
                falseSuccess = true;
                mismatchDescription.appendText("expected error message: ").appendText(message)
                        .appendText(" but got ");
            }
            mismatchDescription.appendText(errorMessagesAsBlock);
            return !falseSuccess;
        }

        ;
    };

}
 
開發者ID:mostlymagic,項目名稱:hacking-java,代碼行數:24,代碼來源:AbstractCompilerTest.java

示例9: containsPropertySource

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
private static Matcher<? super ConfigurableEnvironment> containsPropertySource(
		final String sourceName) {
	return new TypeSafeDiagnosingMatcher<ConfigurableEnvironment>() {
		@Override
		public void describeTo(Description description) {
			description.appendText("environment containing property source ")
					.appendValue(sourceName);
		}

		@Override
		protected boolean matchesSafely(ConfigurableEnvironment item,
				Description mismatchDescription) {
			MutablePropertySources sources = new MutablePropertySources(
					item.getPropertySources());
			ConfigurationPropertySources.finishAndRelocate(sources);
			mismatchDescription.appendText("Not matched against: ")
					.appendValue(sources);
			return sources.contains(sourceName);
		}
	};
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:22,代碼來源:ConfigFileEnvironmentPostProcessorTests.java

示例10: acceptsProfiles

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
private static Matcher<? super ConfigurableEnvironment> acceptsProfiles(
		final String... profiles) {
	return new TypeSafeDiagnosingMatcher<ConfigurableEnvironment>() {
		@Override
		public void describeTo(Description description) {
			description.appendText("environment accepting profiles ")
					.appendValue(profiles);
		}

		@Override
		protected boolean matchesSafely(ConfigurableEnvironment item,
				Description mismatchDescription) {
			mismatchDescription.appendText("Not matched against: ")
					.appendValue(item.getActiveProfiles());
			return item.acceptsProfiles(profiles);
		}
	};
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:19,代碼來源:ConfigFileEnvironmentPostProcessorTests.java

示例11: hasTag

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
public static Matcher<Git> hasTag(final String tag) {
    return new TypeSafeDiagnosingMatcher<Git>() {
        @Override
        protected boolean matchesSafely(Git repo, Description mismatchDescription) {
            try {
                mismatchDescription.appendValueList("a git repo with tags: ", ", ", "", repo.getRepository().getTags().keySet());
                return GitHelper.hasLocalTag(repo, tag);
            } catch (GitAPIException e) {
                throw new RuntimeException("Couldn't access repo", e);
            }
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("a git repo with the tag " + tag);
        }
    };
}
 
開發者ID:danielflower,項目名稱:multi-module-maven-release-plugin,代碼行數:19,代碼來源:GitMatchers.java

示例12: hasCleanWorkingDirectory

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
public static Matcher<Git> hasCleanWorkingDirectory() {
    return new TypeSafeDiagnosingMatcher<Git>() {
        @Override
        protected boolean matchesSafely(Git git, Description mismatchDescription) {
            try {
                Status status = git.status().call();
                if (!status.isClean()) {
                    String start = "Uncommitted changes in ";
                    String end = " at " + git.getRepository().getWorkTree().getAbsolutePath();
                    mismatchDescription.appendValueList(start, ", ", end, status.getUncommittedChanges());
                }
                return status.isClean();
            } catch (GitAPIException e) {
                throw new RuntimeException("Error checking git status", e);
            }
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("A git directory with no staged or unstaged changes");
        }
    };
}
 
開發者ID:danielflower,項目名稱:multi-module-maven-release-plugin,代碼行數:24,代碼來源:GitMatchers.java

示例13: allOf

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
@SafeVarargs
public static <T> Matcher<T> allOf(Matcher<? super T>... matchers) {
    return new TypeSafeDiagnosingMatcher<T>() {
        @Override
        protected boolean matchesSafely(T item, Description mismatchDescription) {
            boolean matches = true;
            for (Matcher<? super T> matcher : matchers) {
                if (!matcher.matches(item)) {
                    if (!matches) mismatchDescription.appendText(", ");
                    matcher.describeMismatch(item, mismatchDescription);
                    matches = false;
                }
            }
            return matches;
        }

        @Override
        public void describeTo(Description description) {
            description.appendList("(", " " + "and" + " ", ")", Arrays.asList(matchers));
        }
    };
}
 
開發者ID:pivotal,項目名稱:executable-dist-plugin,代碼行數:23,代碼來源:MatcherUtils.java

示例14: hasCause

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
public static Matcher<Exception> hasCause(Matcher<? extends Throwable> causeMatcher) {
    return new TypeSafeDiagnosingMatcher<Exception>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("cause should ").appendDescriptionOf(causeMatcher);
        }

        @Override
        protected boolean matchesSafely(Exception e, Description mismatchDescription) {
            Throwable cause = e.getCause();
            boolean matches = causeMatcher.matches(cause);
            if (!matches) {
                mismatchDescription.appendValue(e).appendText(" had cause ").appendValue(cause);
            }
            return matches;
        }
    };
}
 
開發者ID:digipost,項目名稱:digg,代碼行數:20,代碼來源:DiggMatchers.java

示例15: cast

import org.hamcrest.TypeSafeDiagnosingMatcher; //導入依賴的package包/類
private static <T, U> Matcher<U> cast(Class<T> clazz, Matcher<? super T> downcastMatcher) {
    return new TypeSafeDiagnosingMatcher<U>() {
        @Override
        public void describeTo(Description description) {
            downcastMatcher.describeTo(description);
        }

        @Override
        protected boolean matchesSafely(Object item, Description mismatchDescription) {
            if (!clazz.isInstance(item)) {
                mismatchDescription.appendText("was a " + item.getClass().getSimpleName());
                return false;
            } if (downcastMatcher.matches(item)) {
                return true;
            } else {
                downcastMatcher.describeMismatch(item, mismatchDescription);
                return false;
            }
        }
    };
}
 
開發者ID:mwilliamson,項目名稱:java-mammoth,代碼行數:22,代碼來源:DocumentMatchers.java


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