Package org.junit

Examples of org.junit.ComparisonFailure


    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


        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()).toString());
                    }
                } 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().toString(),
                                            sourceTag.getText().toString());
            }
        }
        return true;
View Full Code Here

            String found = q2.get(attr.getKey());
            if (found == null) {
                throw new AssertionError("Attribute: " + attr.getKey() + " is missing.");               
            }
            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.getAttributes(), source.getAttributes(), ignoreAttr);
        assertAttributesEquals(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

                String newMessage = "Database Test Failure on " + database;
                if (e.getMessage() != null) {
                    newMessage += ": " + e.getMessage();
                }

                ComparisonFailure newError = new ComparisonFailure(newMessage, e.getExpected(), e.getActual());
                newError.setStackTrace(e.getStackTrace());
                throw newError;
            } catch (AssertionError e) {
                e.printStackTrace();
                String newMessage = "Database Test Failure on " + database;
                if (e.getMessage() != null) {
                    newMessage += ": " + e.getMessage();
                }

                AssertionError newError = new AssertionError(newMessage);
                newError.setStackTrace(e.getStackTrace());
                throw newError;
            } catch (MigrationFailedException e) {
                e.printStackTrace();
                String newMessage = "Database Test Failure on " + database;
                if (e.getMessage() != null) {
                    newMessage += ": " + e.getMessage();
                }

                AssertionError newError = new AssertionError(newMessage);
                newError.setStackTrace(e.getStackTrace());
                throw newError;
            } catch (Exception e) {
                e.printStackTrace();
                String newMessage = "Database Test Exception on " + database;
                if (e.getMessage() != null) {
                    newMessage += ": " + e.getMessage();
                }
               
                Exception newError = e.getClass().getConstructor(String.class).newInstance(newMessage);
                if (e.getCause() == null) {
                    newError.setStackTrace(e.getStackTrace());
                } else {
                    newError.setStackTrace(e.getCause().getStackTrace());                   
                }
                throw newError;
            } finally {
                if (database.getConnection() != null && !database.getAutoCommitMode()) {
                    database.rollback();
View Full Code Here

          found = true;
          break;
        }
      if(!found) {
        if(predicates.length == 1)
          throw new ComparisonFailure(
            "Predicate does not match", predicates[0].toString(), diagnosticsToString(d));
        throw new ComparisonFailure(
          "No predicate in expected matches", Arrays.toString(predicates), diagnosticsToString(d));
      }
    }
    ArrayList<DiagnosticPredicate> unconsumed = new ArrayList<DiagnosticPredicate>();
    for(Entry<DiagnosticPredicate, Boolean> e : consumed.entrySet())
      if(!e.getValue() && e.getKey().isRequired())
        unconsumed.add(e.getKey());
    if(unconsumed.size() != 0)
      throw new ComparisonFailure(
        "Missing diagnostics for required predicates", Arrays.toString(unconsumed.toArray()),
        diagnosticsToString(asserted));
  }
View Full Code Here

  public void assertAny(Iterable<Diagnostic> asserted, DiagnosticPredicate... predicates) {
    for(DiagnosticPredicate predicate : predicates)
      if(Iterables.any(asserted, predicate))
        return;
    throw new ComparisonFailure(
      "No predicate (any expected) matches diagnostics", Arrays.toString(predicates),
      diagnosticsToString(asserted));

  }
View Full Code Here

   * Warnings and/or errors must be present.
   */
  public void assertErrors() {
    List<Diagnostic> diagnostics = resource.getErrors();
    if(diagnostics.size() < 1)
      throw new ComparisonFailure("Error Diagnostics expected", "> 0 Diagnostics", "");
  }
View Full Code Here

   * @param diag
   */
  public void assertOk() {
    Iterable<Diagnostic> all = getAllDiagnostics();
    if(Iterables.size(all) > 0)
      throw new ComparisonFailure("No diagnostics expected", "No diagnostics", diagnosticsToString(all));
  }
View Full Code Here

  }

  public void assertWarnings() {
    List<Diagnostic> diagnostics = resource.getWarnings();
    if(diagnostics.size() < 1)
      throw new ComparisonFailure("Warning Diagnostics expected", "> 0 Diagnostics", "");
  }
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.