本文整理汇总了Java中org.junit.ComparisonFailure类的典型用法代码示例。如果您正苦于以下问题:Java ComparisonFailure类的具体用法?Java ComparisonFailure怎么用?Java ComparisonFailure使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ComparisonFailure类属于org.junit包,在下文中一共展示了ComparisonFailure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: code_js_with_one_issue
import org.junit.ComparisonFailure; //导入依赖的package包/类
@Test
public void code_js_with_one_issue() throws Exception {
Path path = Paths.get("src/test/resources/code.js");
MultiFileVerifier verifier = MultiFileVerifier.create(path, UTF_8);
verifier.addComment(path, 4, 19, "// Noncompliant", 2, 0);
verifier.reportIssue(path, "issue").onLine(4);
verifier.assertOneOrMoreIssues();
try {
verifier.assertNoIssues();
Assert.fail("Should raise ComparisonFailure.");
} catch (ComparisonFailure failure) {
assertThat(failure.getExpected()).contains("ERROR: 'assertNoIssues()' is called but there's some 'Noncompliant' comments.");
}
}
示例2: execute
import org.junit.ComparisonFailure; //导入依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IStructuredSelection selection = (IStructuredSelection) HandlerUtil.getCurrentSelectionChecked(event);
IWorkbenchWindow[] windows = N4IDEXpectUIPlugin.getDefault().getWorkbench().getWorkbenchWindows();
try {
view = (N4IDEXpectView) windows[0].getActivePage().showView(
N4IDEXpectView.ID);
} catch (PartInitException e) {
N4IDEXpectUIPlugin.logError("cannot refresh test view window", e);
}
Description desc = (Description) selection.getFirstElement();
if (desc.isTest() && view.testsExecutionStatus.hasFailed(desc)) {
Throwable failureException = view.testsExecutionStatus.getFailure(desc).getException();
if (failureException instanceof ComparisonFailure) {
ComparisonFailure cf = (ComparisonFailure) failureException;
// display comparison view
displayComparisonView(cf, desc);
}
}
return null;
}
示例3: displayComparisonView
import org.junit.ComparisonFailure; //导入依赖的package包/类
/**
* Display comparison view of test file with expected and actual xpect expectation
*/
private void displayComparisonView(ComparisonFailure cf, Description desc) {
IXpectURIProvider uriProfider = XpectRunner.INSTANCE.getUriProvider();
IFile fileTest = null;
if (uriProfider instanceof N4IDEXpectTestURIProvider) {
N4IDEXpectTestURIProvider fileCollector = (N4IDEXpectTestURIProvider) uriProfider;
fileTest = ResourcesPlugin.getWorkspace().getRoot()
.getFileForLocation(new Path(fileCollector.findRawLocation(desc)));
}
if (fileTest != null && fileTest.isAccessible()) {
N4IDEXpectCompareEditorInput inp = new N4IDEXpectCompareEditorInput(fileTest, cf);
CompareUI.openCompareEditor(inp);
} else {
throw new RuntimeException("paths in descriptions changed!");
}
}
示例4: assertByteArraySetEquals
import org.junit.ComparisonFailure; //导入依赖的package包/类
public static void assertByteArraySetEquals(Set<byte[]> expected, Set<byte[]> actual) {
assertEquals(expected.size(), actual.size());
Iterator<byte[]> e = expected.iterator();
while (e.hasNext()) {
byte[] next = e.next();
boolean contained = false;
for (byte[] element : expected) {
if (Arrays.equals(next, element)) {
contained = true;
}
}
if (!contained) {
throw new ComparisonFailure("element is missing", Arrays.toString(next), actual.toString());
}
}
}
示例5: match
import org.junit.ComparisonFailure; //导入依赖的package包/类
@Override
public void match(MvcResult result) throws Exception {
String content = result.getResponse().getContentAsString();
final JsonParser parser = new JsonParser();
final JsonElement actual = parser.parse(content);
if (actual.isJsonPrimitive()) {
final JsonElement expected = parser.parse(expectedJsonResponse);
assertThat(actual, is(expected));
} else {
try {
JSONAssert.assertEquals(expectedJsonResponse, content, false);
} catch (AssertionError e) {
throw new ComparisonFailure(e.getMessage(), expectedJsonResponse, content);
}
}
}
示例6: checkByFile
import org.junit.ComparisonFailure; //导入依赖的package包/类
public void checkByFile(TaskFile taskFile, String fileName, boolean useLength) {
Pair<Document, List<AnswerPlaceholder>> placeholders = getPlaceholders(fileName, useLength, true);
String message = "Placeholders don't match";
if (taskFile.getActivePlaceholders().size() != placeholders.second.size()) {
throw new ComparisonFailure(message,
CCTestsUtil.getPlaceholdersPresentation(taskFile.getActivePlaceholders()),
CCTestsUtil.getPlaceholdersPresentation(placeholders.second));
}
for (AnswerPlaceholder answerPlaceholder : placeholders.getSecond()) {
AnswerPlaceholder placeholder = taskFile.getAnswerPlaceholder(answerPlaceholder.getOffset());
if (!CCTestsUtil.comparePlaceholders(placeholder, answerPlaceholder)) {
throw new ComparisonFailure(message,
CCTestsUtil.getPlaceholdersPresentation(taskFile.getActivePlaceholders()),
CCTestsUtil.getPlaceholdersPresentation(placeholders.second));
}
}
}
示例7: canCompile
import org.junit.ComparisonFailure; //导入依赖的package包/类
@Test
public void canCompile() throws LoaderException, Twig4jRuntimeException {
ClassCompiler compiler = new ClassCompiler(new Environment());
Hash hash = new Hash(1);
hash.putAttribute("foo", new Constant("Foo", 1));
hash.putAttribute("bar", new Constant("Bar", 1));
hash.compile(compiler);
// Since it's a hashmap we're not sure of the order of the attributes so just try both
try {
Assert.assertEquals(
"Compiled source code should be valid java array",
"((new org.twig4j.core.util.HashMap()).put(\"foo\", \"Foo\").put(\"bar\", \"Bar\"))",
compiler.getSourceCode()
);
} catch (ComparisonFailure e) {
Assert.assertEquals(
"Compiled source code should be valid java array",
"((new org.twig4j.core.util.HashMap()).put(\"bar\", \"Bar\").put(\"foo\", \"Foo\"))",
compiler.getSourceCode()
);
}
}
示例8: assertCourseVariants
import org.junit.ComparisonFailure; //导入依赖的package包/类
private void assertCourseVariants(List<List<CourseControlRowData>> variantList, String[][] codes) throws ComparisonFailure {
int successCounter = 0;
ComparisonFailure lastException = null;
for (List<CourseControlRowData> course : variantList) {
for (String[] codeList : codes) {
try {
assertCourse(course, codeList);
successCounter++;
}
catch (ComparisonFailure e) {
lastException = e;
}
}
}
if (successCounter != variantList.size()) {
throw lastException;
}
}
示例9: assertEquals
import org.junit.ComparisonFailure; //导入依赖的package包/类
protected void assertEquals(Set<byte[]> expected, Set<byte[]> actual) {
assertEquals(expected.size(), actual.size());
Iterator<byte[]> e = expected.iterator();
while (e.hasNext()) {
byte[] next = e.next();
boolean contained = false;
for (byte[] element : expected) {
if (Arrays.equals(next, element)) {
contained = true;
}
}
if (!contained) {
throw new ComparisonFailure("element is missing", Arrays.toString(next), actual.toString());
}
}
}
示例10: prepareTaskAs
import org.junit.ComparisonFailure; //导入依赖的package包/类
private void prepareTaskAs(Runnable runnable, String lastName) {
range(0, TIMES).forEach(i -> {
tasks.add(() -> {
Session.login(lastName);
try {
runnable.run();
} catch (ComparisonFailure failure) {
throw new ComparisonFailure(lastName + ": " + failure.getMessage(),
failure.getExpected(), failure.getActual());
} finally {
Session.logout();
}
return lastName;
});
});
}
开发者ID:lordlothar99,项目名称:strategy-spring-security-acl,代码行数:17,代码来源:MultithreadCustomerRepositoryTest.java
示例11: processFile
import org.junit.ComparisonFailure; //导入依赖的package包/类
@Override
public String processFile(String completeData, String data, int offset, int len, String change) throws Exception {
IParseResult initialParseResult = parser.parse(new StringReader(data));
String newData = applyDelta(data, offset, len, change);
ReplaceRegion replaceRegion = new ReplaceRegion(offset, len, change);
try {
IParseResult reparsed = parser.reparse(initialParseResult, replaceRegion);
IParseResult parsedFromScratch = parser.parse(new StringReader(newData));
assertEqual(data, newData, parsedFromScratch, reparsed);
return newData;
} catch(Throwable e) {
ComparisonFailure throwMe = new ComparisonFailure(e.getMessage(), newData, replaceRegion + DELIM + data);
throwMe.initCause(e);
throw throwMe;
}
}
示例12: assertArraysAreSameLength
import org.junit.ComparisonFailure; //导入依赖的package包/类
private int assertArraysAreSameLength(Object expecteds, Object actuals, String header) {
if (expecteds == null) {
Assert.fail(header + "expected array was null");
}
if (actuals == null) {
Assert.fail(header + "actual array was null");
}
int actualsLength = Array.getLength(actuals);
int expectedsLength = Array.getLength(expecteds);
if (actualsLength != expectedsLength) {
throw new ComparisonFailure(header + "array lengths differed, expected.length=" + expectedsLength + " actual.length=" + actualsLength, TestUtils.arrayAsString(expecteds), TestUtils.arrayAsString(actuals));
}
return expectedsLength;
}
示例13: testBoundaryMatchers6_G_TheEndOfThePreviousMatch_MISSING_FEATURE
import org.junit.ComparisonFailure; //导入依赖的package包/类
/**
* See <a href="http://www.regular-expressions.info/continue.html>Continuing at The End of The Previous Match</a>
*
* @throws Exception
*/
@Test
public void testBoundaryMatchers6_G_TheEndOfThePreviousMatch_MISSING_FEATURE() throws Exception {
// it's nice that this works here but this is because it matches at
// EVERY position here
assertReplacementByReader("yzyz", "\\G(y|z)", "x", 1, 1024, "xxxx", 0);
assertReplacementByReader("yzyzyzyzyzyz", "\\G(y|z)", "x", 1, 2, "xxxxxxxxxxxx", 0);
// there are other cases that are not supported:
try {
assertReplacementByReader("azyzazyz", "(y)|(\\Gz)", "x", 1, 2, "azxxazxx", 0);
fail("ComparisonFailure expected");
} catch (ComparisonFailure e) {
assertEquals("expected:<a[zxxaz]xx> but was:<a[xxxax]xx>", e.getMessage());
}
}
示例14: testXmlVersion_utf8Bom_withoutByteSkippingReader
import org.junit.ComparisonFailure; //导入依赖的package包/类
@Test
public void testXmlVersion_utf8Bom_withoutByteSkippingReader() throws Exception {
byte UTF8_BOM_BYTE_1 = (byte) 0xEF;
byte UTF8_BOM_BYTE_2 = (byte) 0xBB;
byte UTF8_BOM_BYTE_3 = (byte) 0xBF;
// version in prolog is 1.0
String input = "<?xml version='1.0'>";
byte[] bytes = input.getBytes();
byte[] bytesWithUtf8Bom = new byte[bytes.length + 3];
bytesWithUtf8Bom[0] = UTF8_BOM_BYTE_1;
bytesWithUtf8Bom[1] = UTF8_BOM_BYTE_2;
bytesWithUtf8Bom[2] = UTF8_BOM_BYTE_3;
System.arraycopy(bytes, 0, bytesWithUtf8Bom, 3, bytes.length);
String inputWithBom = new String(bytesWithUtf8Bom);
// System.out.println("inputWithBom: " + inputWithBom);
try {
assertXmlVersionInProlog(inputWithBom, "1.1", "<?xml version='1.1'>");
fail("AssertionError expected");
} catch (ComparisonFailure e) {
// OK
}
}
示例15: assertCollectionEquals
import org.junit.ComparisonFailure; //导入依赖的package包/类
/** Assert two iterable objects have the same elements.
*
* @param <T> the type of the elements in the iterable objects.
* @param expected the expected value.
* @param actual the actual value.
*/
public static <T> void assertCollectionEquals(Iterable<? extends T> expected, Iterable<? extends T> actual) {
final Iterator<? extends T> it1 = expected.iterator();
final Iterator<? extends T> it2 = actual.iterator();
while (it1.hasNext()) {
if (!it2.hasNext()) {
throw new ComparisonFailure(
formatFailMessage(null, "Element is missed", expected, actual), //$NON-NLS-1$
toString(expected), toString(actual));
}
final T expect = it1.next();
final T act = it2.next();
if (!Objects.equals(expect, act)) {
throw new ComparisonFailure(formatFailMessage(null, "Not same element", expected, actual), //$NON-NLS-1$
toString(expected), toString(actual));
}
}
if (it2.hasNext()) {
throw new ComparisonFailure(formatFailMessage(null, "Too many elements", expected, actual), //$NON-NLS-1$
toString(expected), toString(actual));
}
}