Example usage for java.lang AssertionError getLocalizedMessage

List of usage examples for java.lang AssertionError getLocalizedMessage

Introduction

In this page you can find the example usage for java.lang AssertionError getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:org.kalypso.commons.junit.FileAssert.java

/**
 * Asserts that the contents of two files is equal.
 *//*w  w w.  j  a v a 2 s .  c om*/
public static void assertFileContentEquals(final File expected, final File actual) {
    try {
        final List<String> actualLines = FileUtils.readLines(actual, (Charset) null);
        final List<String> expectedLines = FileUtils.readLines(expected, (Charset) null);

        final Iterator<String> actualIt = actualLines.iterator();
        final Iterator<String> expectedIt = expectedLines.iterator();

        int count = 0;
        while (expectedIt.hasNext() && actualIt.hasNext()) {
            count++;

            final Object expectedLine = expectedIt.next();
            final Object actualLine = actualIt.next();

            try {
                Assert.assertEquals(expectedLine, actualLine);
            } catch (final AssertionError e) {
                final String msg = String.format("Line %d: %s", count, e.getLocalizedMessage()); //$NON-NLS-1$
                fail(msg);
            }
        }

        assertIteratorIsEmpty("Actual file is longer than expected: ", actualIt); //$NON-NLS-1$
        assertIteratorIsEmpty("Expected file is longer than actual: ", expectedIt); //$NON-NLS-1$
    } catch (final IOException e) {
        e.printStackTrace();
        Assert.fail("Failed to access file: " + e.getLocalizedMessage()); //$NON-NLS-1$
    }
}