@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."); } }
@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; }
/** * 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!"); } }
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()); } } }
@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); } } }
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)); } } }
public static Matcher<ClassSpec> generatesTo(String expectedTestFile) { return new TypeSafeMatcher<ClassSpec>() { @Override protected boolean matchesSafely(ClassSpec spec) { String expectedClass = getExpectedClass(spec, expectedTestFile); String actualClass = generateClass(spec); try { assertThat(actualClass, equalToIgnoringWhiteSpace(expectedClass)); } catch (AssertionError e) { //Unfortunately for string comparisons Hamcrest doesn't really give us a nice diff. On the other hand //IDEs know how to nicely display JUnit's ComparisonFailure - makes debugging tests much easier throw new ComparisonFailure(String.format("Output class does not match expected [test-file: %s]", expectedTestFile), expectedClass, actualClass); } return true; } @Override public void describeTo(Description description) { //Since we bubble an exception this will never actually get called } }; }
@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() ); } }
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; } }
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()); } } }
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; }); }); }
@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; } }
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; }
/** * 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()); } }
@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 } }
/** 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)); } }
/** Test if the two collections contain the same elements without * taking into account the order of the elements in the collections. * * @param <T> the type of the elements in the collections. * @param message the error message. * @param expected the expected collection. * @param actual the actual collection. */ public static <T> void assertEpsilonEquals(String message, Collection<? extends T> expected, Collection<? extends T> actual) { final List<T> l = new ArrayList<>(actual); for (final T e : expected) { if (!l.remove(e)) { throw new ComparisonFailure( formatFailMessage(message, "not similar collections", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } } if (!l.isEmpty()) { throw new ComparisonFailure( formatFailMessage(message, "not similar collections, not expected elements", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } }
/** Test if the two collections contain the same elements without * taking into account the order of the elements in the collections. * * @param <T> the type of the elements in the collections. * @param message the error message. * @param expected the expected collection. * @param actual the actual collection. */ public static <T> void assertEpsilonEquals(String message, T[] expected, T[] actual) { final List<T> l = new ArrayList<>(Arrays.asList(actual)); for (final T e : expected) { if (!l.remove(e)) { throw new ComparisonFailure( formatFailMessage(message, "not similar collections", expected, actual), //$NON-NLS-1$ Arrays.toString(expected), Arrays.toString(actual)); } } if (!l.isEmpty()) { throw new ComparisonFailure( formatFailMessage(message, "not similar collections, not expected elements", expected, actual), //$NON-NLS-1$ Arrays.toString(expected), Arrays.toString(actual)); } }
/** Test if the actual value is not equal to the expected value with * a distance of epsilon. * * @param message * @param expected * @param actual */ protected void assertNotEpsilonEquals(String message, Tuple3D<?> expected, Tuple3D<?> actual) { if (isEpsilonEquals(expected.getX(), actual.getX(), false)) { throw new ComparisonFailure( (message==null ? "" : (message+": ")) +"not same x value", expected.toString(), actual.toString()); } if (isEpsilonEquals(expected.getY(), actual.getY(), false)) { throw new ComparisonFailure( (message==null ? "" : (message+": ")) +"not same y value", expected.toString(), actual.toString()); } if (isEpsilonEquals(expected.getZ(), actual.getZ(), false)) { throw new ComparisonFailure( (message==null ? "" : (message+": ")) +"not same z value", expected.toString(), actual.toString()); } }
/** Test if the actual value is equal to the expected value with * a distance of epsilon. * * @param message * @param expected * @param actual */ protected void assertEpsilonEquals(String message, Tuple3D<?> expected, Tuple3D<?> actual) { if (!isEpsilonEquals(expected.getX(), actual.getX())) { throw new ComparisonFailure( (message==null ? "" : (message+": ")) +"not same x value", expected.toString(), actual.toString()); } if (!isEpsilonEquals(expected.getY(), actual.getY())) { throw new ComparisonFailure( (message==null ? "" : (message+": ")) +"not same y value", expected.toString(), actual.toString()); } if (!isEpsilonEquals(expected.getZ(), actual.getZ())) { throw new ComparisonFailure( (message==null ? "" : (message+": ")) +"not same z value", expected.toString(), actual.toString()); } }
/** Test if the actual value is equal to the expected value with * a distance of epsilon. * * @param message * @param expected * @param actual */ protected void assertEpsilonEquals(String message, Tuple2D<?> expected, Tuple2D<?> actual) { if (!isEpsilonEquals(expected.getX(), actual.getX())) { throw new ComparisonFailure( (message==null ? "" : (message+": ")) +"not same x value", expected.toString(), actual.toString()); } if (!isEpsilonEquals(expected.getY(), actual.getY())) { throw new ComparisonFailure( (message==null ? "" : (message+": ")) +"not same y value", expected.toString(), actual.toString()); } }
/** Test if the actual value is not equal to the expected value with * a distance of epsilon. * * @param message * @param expected * @param actual */ protected void assertNotEpsilonEquals(String message, Tuple2D<?> expected, Tuple2D<?> actual) { if (isEpsilonEquals(expected.getX(), actual.getX(), false)) { throw new ComparisonFailure( (message==null ? "" : (message+": ")) +"not same x value", expected.toString(), actual.toString()); } if (isEpsilonEquals(expected.getY(), actual.getY(), false)) { throw new ComparisonFailure( (message==null ? "" : (message+": ")) +"not same y value", expected.toString(), actual.toString()); } }
public final void assertEpsilonEquals(double expectedX, double expectedY, PowerResult<?> actual) { if (actual == null) { fail("Result is null"); //$NON-NLS-1$ return; } if (!actual.isVectorial()) { throw new ComparisonFailure("Not same result type", "[" + expectedX + ";" + expectedY + "]", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ actual.toString()); } Vector3D<?, ?> vector = actual.getVector(); assert (vector != null); if (!isEpsilonEquals(expectedX, vector.getX()) || !isEpsilonEquals(expectedY, vector.getY())) { throw new ComparisonFailure("Not same result type", "[" + expectedX + ";" + expectedY + "]", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ actual.toString()); } }
public final void assertEpsilonEquals(double expectedX, double expectedY, PowerResult<?> actual) { if (actual == null) { fail("Result is null"); //$NON-NLS-1$ return; } if (!actual.isVectorial()) { throw new ComparisonFailure("Not same result type", "[" + expectedX + ";" + expectedY + "]", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ actual.toString()); } Vector2D<?, ?> vector = actual.getVector(); assert (vector != null); if (!isEpsilonEquals(expectedX, vector.getX()) || !isEpsilonEquals(expectedY, vector.getY())) { throw new ComparisonFailure("Not same result type", "[" + expectedX + ";" + expectedY + "]", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ actual.toString()); } }
/** Assert is the given path iterator has a first element with the * given information. * * @param pi the path iterator. * @param type the expected type. * @param coords the expected coordinates. */ public void assertElement(PathIterator2afp<?> pi, PathElementType type, double... coords) { if (!pi.hasNext()) { fail("expected path element but the iterator is empty"); //$NON-NLS-1$ } PathElement2afp pe = pi.next(); if (!type.equals(pe.getType())) { throw new ComparisonFailure("not same element type.", type.name(), pe.getType().name()); //$NON-NLS-1$ } double[] c = new double[coords.length]; pe.toArray(c); if (!isEpsilonEquals(c, coords)) { throw new ComparisonFailure("not same coordinates.", //$NON-NLS-1$ Arrays.toString(coords), Arrays.toString(c)); } }
/** Assert is the given path iterator has a first element with the * given information. * * @param pi the path iterator. * @param type the expected type. * @param coords the expected coordinates. */ protected void assertElement(PathIterator3afp<?> pi, PathElementType type, double... coords) { if (!pi.hasNext()) { fail("expected path element but the iterator is empty"); //$NON-NLS-1$ } PathElement3afp pe = pi.next(); if (!type.equals(pe.getType())) { throw new ComparisonFailure("not same element type.", type.name(), pe.getType().name()); //$NON-NLS-1$ } double[] c = new double[coords.length]; pe.toArray(c); if (!isEpsilonEquals(c, coords)) { throw new ComparisonFailure("not same coordinates.", //$NON-NLS-1$ Arrays.toString(coords), Arrays.toString(c)); } }
/** Test if the actual value is equal to the expected value with * a distance of epsilon. * * @param message the error message. * @param expected the expected value. * @param actual the actual value. */ public void assertEpsilonEquals(String message, Tuple3D<?> expected, Tuple3D<?> actual) { if (!isEpsilonEquals(expected.getX(), actual.getX())) { throw new ComparisonFailure( formatFailMessage(message, "not same x value", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } if (!isEpsilonEquals(expected.getY(), actual.getY())) { throw new ComparisonFailure( formatFailMessage(message, "not same y value", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } if (!isEpsilonEquals(expected.getZ(), actual.getZ())) { throw new ComparisonFailure( formatFailMessage(message, "not same z value", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } }
/** Test if the actual value is not equal to the expected value with * a distance of epsilon. * * @param message the error message. * @param expected the expected value. * @param actual the actual value. */ public void assertNotEpsilonEquals(String message, Tuple3D<?> expected, Tuple3D<?> actual) { if (isEpsilonEquals(expected.getX(), actual.getX(), false)) { throw new ComparisonFailure( formatFailMessage(message, "not same x value", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } if (isEpsilonEquals(expected.getY(), actual.getY(), false)) { throw new ComparisonFailure( formatFailMessage(message, "not same y value", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } if (isEpsilonEquals(expected.getZ(), actual.getZ(), false)) { throw new ComparisonFailure( formatFailMessage(message, "not same z value", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } }
/** Test if the actual matrix is equal to the expected values. * * @param expected the expected value. * @param actual the actual value. */ public void assertEpsilonEquals(Matrix3d expected, Matrix3d actual) { if ((!isEpsilonEquals(expected.getM00(), actual.getM00())) ||(!isEpsilonEquals(expected.getM01(), actual.getM01())) ||(!isEpsilonEquals(expected.getM02(), actual.getM02())) ||(!isEpsilonEquals(expected.getM10(), actual.getM10())) ||(!isEpsilonEquals(expected.getM11(), actual.getM11())) ||(!isEpsilonEquals(expected.getM12(), actual.getM12())) ||(!isEpsilonEquals(expected.getM20(), actual.getM20())) ||(!isEpsilonEquals(expected.getM21(), actual.getM21())) ||(!isEpsilonEquals(expected.getM22(), actual.getM22()))) { throw new ComparisonFailure( formatFailMessage(null, "Not same matrices", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } }
/** Test if the actual matrix is different from the expected values. * * @param expected the expected value. * @param actual the actual value. */ public void assertNotEpsilonEquals(Matrix3d expected, Matrix3d actual) { if ((isEpsilonEquals(expected.getM00(), actual.getM00())) &&(isEpsilonEquals(expected.getM01(), actual.getM01())) &&(isEpsilonEquals(expected.getM02(), actual.getM02())) &&(isEpsilonEquals(expected.getM10(), actual.getM10())) &&(isEpsilonEquals(expected.getM11(), actual.getM11())) &&(isEpsilonEquals(expected.getM12(), actual.getM12())) &&(isEpsilonEquals(expected.getM20(), actual.getM20())) &&(isEpsilonEquals(expected.getM21(), actual.getM21())) &&(isEpsilonEquals(expected.getM22(), actual.getM22()))) { throw new ComparisonFailure( formatFailMessage(null, "Not same matrices", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } }
/** Test if the actual matrix is equal to the expected values. * * @param expected the expected value. * @param actual the actual value. */ public void assertEpsilonEquals(Matrix4d expected, Matrix4d actual) { if ((!isEpsilonEquals(expected.getM00(), actual.getM00())) ||(!isEpsilonEquals(expected.getM01(), actual.getM01())) ||(!isEpsilonEquals(expected.getM02(), actual.getM02())) ||(!isEpsilonEquals(expected.getM03(), actual.getM03())) ||(!isEpsilonEquals(expected.getM10(), actual.getM10())) ||(!isEpsilonEquals(expected.getM11(), actual.getM11())) ||(!isEpsilonEquals(expected.getM12(), actual.getM12())) ||(!isEpsilonEquals(expected.getM13(), actual.getM13())) ||(!isEpsilonEquals(expected.getM20(), actual.getM20())) ||(!isEpsilonEquals(expected.getM21(), actual.getM21())) ||(!isEpsilonEquals(expected.getM22(), actual.getM22())) ||(!isEpsilonEquals(expected.getM23(), actual.getM23())) ||(!isEpsilonEquals(expected.getM30(), actual.getM30())) ||(!isEpsilonEquals(expected.getM31(), actual.getM31())) ||(!isEpsilonEquals(expected.getM32(), actual.getM32())) ||(!isEpsilonEquals(expected.getM33(), actual.getM33()))) { throw new ComparisonFailure( formatFailMessage(null, "Not same matrices", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } }
/** Test if the actual matrix is different from the expected values. * * @param expected the expected value. * @param actual the actual value. */ public void assertNotEpsilonEquals(Matrix4d expected, Matrix4d actual) { if ((isEpsilonEquals(expected.getM00(), actual.getM00())) &&(isEpsilonEquals(expected.getM01(), actual.getM01())) &&(isEpsilonEquals(expected.getM02(), actual.getM02())) &&(isEpsilonEquals(expected.getM03(), actual.getM03())) &&(isEpsilonEquals(expected.getM10(), actual.getM10())) &&(isEpsilonEquals(expected.getM11(), actual.getM11())) &&(isEpsilonEquals(expected.getM12(), actual.getM12())) &&(isEpsilonEquals(expected.getM13(), actual.getM13())) &&(isEpsilonEquals(expected.getM20(), actual.getM20())) &&(isEpsilonEquals(expected.getM21(), actual.getM21())) &&(isEpsilonEquals(expected.getM22(), actual.getM22())) &&(isEpsilonEquals(expected.getM23(), actual.getM23())) &&(isEpsilonEquals(expected.getM30(), actual.getM30())) &&(isEpsilonEquals(expected.getM31(), actual.getM31())) &&(isEpsilonEquals(expected.getM32(), actual.getM32())) &&(isEpsilonEquals(expected.getM33(), actual.getM33()))) { throw new ComparisonFailure( formatFailMessage(null, "Not same matrices", expected, actual), //$NON-NLS-1$ expected.toString(), actual.toString()); } }
private void assertClasspathEquals(Iterator<URL> actuals, String... expecteds) { assertNotNull(actuals); List<URL> list = new ArrayList<>(); while (actuals.hasNext()) { list.add(actuals.next()); } String[] tab = new String[list.size()]; for (int i = 0; i < tab.length; ++i) { tab[i] = toString(list.get(i)); } try { assertArrayEquals(expecteds, tab); } catch (Throwable exception) { throw new ComparisonFailure(exception.getMessage(), Arrays.toString(expecteds).replaceAll(" +", "\n"), Arrays.toString(tab).replaceAll(" +", "\n")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } }
@Test public final void testAssertCauseMessage() { // PREPARE final Exception second = new RuntimeException("second"); final Exception first = new RuntimeException("first", second); // TEST & VERIFY Units4JUtils.assertCauseMessage(first, "second"); try { Units4JUtils.assertCauseMessage(first, "xxx"); fail(); } catch (final ComparisonFailure f) { // OK assertThat(f.getMessage()).isEqualTo( "expected:<\"[xxx]\"> but was:<\"[second]\">"); } }
@Test public final void testAssertCauseCauseMessage() { // PREPARE final Exception third = new RuntimeException("third"); final Exception second = new RuntimeException("second", third); final Exception first = new RuntimeException("first", second); // TEST & VERIFY Units4JUtils.assertCauseCauseMessage(first, "third"); try { Units4JUtils.assertCauseCauseMessage(first, "xxx"); fail(); } catch (final ComparisonFailure f) { // OK assertThat(f.getMessage()).isEqualTo( "expected:<\"[xxx]\"> but was:<\"[third]\">"); } }
@Test public void code_js_without_issue() throws Exception { Path path = Paths.get("src/test/resources/code.js"); MultiFileVerifier verifier = MultiFileVerifier.create(path, UTF_8); // no addComment(...) // no reportIssue(...) verifier.assertNoIssues(); try { verifier.assertOneOrMoreIssues(); Assert.fail("Should raise ComparisonFailure."); } catch (ComparisonFailure failure) { assertThat(failure.getExpected()).contains("ERROR: 'assertOneOrMoreIssues()' is called but there's no 'Noncompliant' comments."); } }
/** * Asserts the actual events with the expected ones. * * @param sessionId * the unique ID of the session that has to be checked. * @param expectedEvents * the expected events to assert against the actual ones. */ public void assertEquals(final String sessionId, final Iterable<String> expectedEvents) { assertNotNull("Queue was not initialized. One should call #init(int) before invoking #assertEquals()", latch); try { latch.await(20L, SECONDS); unregisterSupplier.get(); } catch (final InterruptedException e) { throw new AssertionError("Time outed while waiting to receive all expected test events.", e); } final Collection<String> eventsForSession = events.get(sessionId); if (size(expectedEvents) != eventsForSession.size()) { throw new ComparisonFailure("Expected:", toString(expectedEvents), toString(eventsForSession)); } final Iterator<String> actItr = eventsForSession.iterator(); final Iterator<String> expItr = expectedEvents.iterator(); while (expItr.hasNext()) { if (!actItr.hasNext()) { throw new ComparisonFailure("Expected:", toString(expectedEvents), toString(eventsForSession)); } final String expected = expItr.next(); final String actual = actItr.next(); if (null == expected || null == actual) { if (expected != actual) { throw new ComparisonFailure("Expected:", toString(expectedEvents), toString(eventsForSession)); } } else { if (!expected.equals(actual)) { throw new ComparisonFailure("Expected:", toString(expectedEvents), toString(eventsForSession)); } } Assert.assertEquals(expected, actual); } }
/** */ public N4IDEXpectCompareEditorInput(IFile file, ComparisonFailure cf) { super(createConfiguration(file)); Preconditions.checkNotNull(file); this.file = file; this.comparisonFailure = cf; }