当前位置: 首页>>代码示例>>Java>>正文


Java ComparisonFailure类代码示例

本文整理汇总了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.");
  }
}
 
开发者ID:SonarSource,项目名称:sonar-analyzer-commons,代码行数:18,代码来源:MultiFileVerifierTest.java

示例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;
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:26,代码来源:XpectCompareCommandHandler.java

示例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!");
	}
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:20,代码来源:XpectCompareCommandHandler.java

示例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());
    }
  }
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:17,代码来源:AssertUtil.java

示例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);
        }
    }
}
 
开发者ID:tyro,项目名称:pact-spring-mvc,代码行数:19,代码来源:JsonResponseBodyMatcher.java

示例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));
    }
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:18,代码来源:CCTestCase.java

示例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()
        );
    }
}
 
开发者ID:palmfjord,项目名称:twig4j-core,代码行数:26,代码来源:HashTests.java

示例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;
  }
}
 
开发者ID:innovad,项目名称:4mila-1.0,代码行数:19,代码来源:IOF300CourseImporterTest.java

示例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());
    }
  }
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:17,代码来源:JedisCommandTestBase.java

示例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;
	}
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:18,代码来源:PartialParsingProcessor.java

示例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;
}
 
开发者ID:vsch,项目名称:idea-multimarkdown,代码行数:18,代码来源:OrderedComparisonCriteria.java

示例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());
    }
}
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:22,代码来源:RegexModifierUnitTest.java

示例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
    }
}
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:25,代码来源:XmlVersionModifierTest.java

示例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));
	}
}
 
开发者ID:gallandarakhneorg,项目名称:afc,代码行数:28,代码来源:AbstractTestCase.java


注:本文中的org.junit.ComparisonFailure类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。