Package org.junit

Examples of org.junit.ComparisonFailure


                throw new AssertionError("Attribute: " + attr.getKey()
                                         + " is missing in "
                                         + element);
            }
            if (!found.equals(attr.getValue())) {
                throw new ComparisonFailure("Attribute not equal: ",
                                            attr.getKey() + ":" + attr.getValue(),
                                            attr.getKey() + ":" + found);
            }
        }
    }
View Full Code Here


    protected void assertTagEquals(Tag expected, Tag source,
                                   final List<String> ignoreAttr,
                                   final List<String> ignoreTag) {
        if (!expected.getName().equals(source.getName())) {
            throw new ComparisonFailure("Tags not equal: ",
                                        expected.getName().toString(),
                                        source.getName().toString());
        }

        assertAttributesEquals(expected.getName(),
                               expected.getAttributes(), source.getAttributes(), ignoreAttr);
        assertAttributesEquals(expected.getName(),
                               source.getAttributes(), expected.getAttributes(), ignoreAttr);

        if (!StringUtils.isEmpty(expected.getText())
                && !expected.getText().equals(source.getText())) {
            throw new ComparisonFailure("Text not equal: ",
                                        expected.getText().toString(),
                                        source.getText().toString());
        }

        if (!expected.getTags().isEmpty()) {
View Full Code Here

    }
    return type;
  }

  public static AssertionError comparisonFailure(String message, String expected, String actual) {
    return new ComparisonFailure(message, expected, actual);
  }
View Full Code Here

        Iterator<Tag> iterator = sourceTags.iterator();

        for (Tag expectedTag : expectedTags) {
            Tag sourceTag = iterator.next();
            if (!expectedTag.getName().equals(sourceTag.getName())) {
                throw new ComparisonFailure("Tags not equal: ",
                                            expectedTag.getName().toString(),
                                            sourceTag.getName().toString());
            }
            for (Map.Entry<QName, String> attr : expectedTag.getAttributes().entrySet()) {
                if (ignoreAttr.contains(attr.getKey().getLocalPart())) {
                    continue;
                }

                if (sourceTag.getAttributes().containsKey(attr.getKey())) {
                    if (!sourceTag.getAttributes().get(attr.getKey()).equals(attr.getValue())) {
                        throw new ComparisonFailure("Attributes not equal: ",
                                                attr.getKey() + ":" + attr.getValue(),
                                                attr.getKey() + ":"
                                                + sourceTag.getAttributes().get(attr.getKey()));
                    }
                } else {
                    throw new AssertionError("Attribute: " + attr + " is missing in the source file.");
                }
            }

            if (!StringUtils.isEmpty(expectedTag.getText())
                && !expectedTag.getText().equals(sourceTag.getText())) {
                throw new ComparisonFailure("Text not equal: ",
                                            expectedTag.getText(),
                                            sourceTag.getText());
            }
        }
        return true;
View Full Code Here

                throw new AssertionError("Attribute: " + attr.getKey()
                                         + " is missing in "
                                         + element);
            }
            if (!found.equals(attr.getValue())) {
                throw new ComparisonFailure("Attribute not equal: ",
                                            attr.getKey() + ":" + attr.getValue(),
                                            attr.getKey() + ":" + found);
            }
        }
    }
View Full Code Here

    protected void assertTagEquals(Tag expected, Tag source,
                                   final List<String> ignoreAttr,
                                   final List<String> ignoreTag) {
        if (!expected.getName().equals(source.getName())) {
            throw new ComparisonFailure("Tags not equal: ",
                                        expected.getName().toString(),
                                        source.getName().toString());
        }

        assertAttributesEquals(expected.getName(),
                               expected.getAttributes(), source.getAttributes(), ignoreAttr);
        assertAttributesEquals(expected.getName(),
                               source.getAttributes(), expected.getAttributes(), ignoreAttr);

        if (!StringUtils.isEmpty(expected.getText())
                && !expected.getText().equals(source.getText())) {
            throw new ComparisonFailure("Text not equal: ",
                                        expected.getText(),
                                        source.getText());
        }

        if (!expected.getTags().isEmpty()) {
View Full Code Here

    public static void assertStartsWith(String expected, String actual) {
        if (actual != null && actual.startsWith(expected)) {
            return;
        } else if (expected instanceof String && actual instanceof String) {
            throw new ComparisonFailure("", (String) expected, (String) actual);
        } else {
            fail(format0("", expected, actual));
        }
    }
View Full Code Here

                                                  String expected, String actual,
                                                  String regex)
            throws IOException {
        CompareWithoutHashes comparer = new CompareWithoutHashes(regex);
        if (!comparer.match(new StringReader(expected), new StringReader(actual)))
            throw new ComparisonFailure(caseName, comparer.converter(expected,actual), actual);
    }
View Full Code Here

    }

    @Override
    protected boolean matchesSafely(String actual, Description mismatchDescription) {
        if (!expected.equals(actual)) {
            String compactedMismatch = new ComparisonFailure("did not match:", expected, actual).getMessage();
            mismatchDescription.appendText(compactedMismatch);
            return false;
        }
        return true;
    }
View Full Code Here

                error.setStackTrace(cause.getStackTrace());
                failure = new Failure(description, error);
            } else if ("com.redhat.ceylon.compiler.java.test.runtime.ComparisonFailed".equals(cause.getClass().getName())) {
                Object expected = get(cause, "getExpected");
                Object got = get(cause, "getGot");
                ComparisonFailure error = new ComparisonFailure(cause.getMessage(), String.valueOf(expected), String.valueOf(got));
                error.setStackTrace(cause.getStackTrace());
                failure = new Failure(description, error);
            } else {
                failure = new Failure(description, e);
            }
        } catch (Exception e) {
View Full Code Here

TOP

Related Classes of org.junit.ComparisonFailure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.