X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Ftest%2FTestCase.java;h=4e7d3800c5a588bf6a1b06f341bfc5d3c2c8c2ac;hb=534332fff48954b4d26c6394a79d7a7aff605f67;hp=a62cb0b79646752fb9b37ffca7c4173dc795cac7;hpb=0988831f084e27de9927c1bb29e338e9263bfa42;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/test/TestCase.java b/src/be/nikiroo/utils/test/TestCase.java index a62cb0b..4e7d380 100644 --- a/src/be/nikiroo/utils/test/TestCase.java +++ b/src/be/nikiroo/utils/test/TestCase.java @@ -1,5 +1,7 @@ package be.nikiroo.utils.test; +import java.util.List; + /** * A {@link TestCase} that can be run with {@link TestLauncher}. * @@ -42,7 +44,6 @@ abstract public class TestCase { * @throws Exception * in case of error */ - @SuppressWarnings("unused") public void setUp() throws Exception { } @@ -52,7 +53,6 @@ abstract public class TestCase { * @throws Exception * in case of error */ - @SuppressWarnings("unused") public void tearDown() throws Exception { } @@ -140,7 +140,7 @@ abstract public class TestCase { } /** - * Check that 2 {@link Object}s are equals. + * Check that 2 longs are equals. * * @param expected * the expected value @@ -155,7 +155,7 @@ abstract public class TestCase { } /** - * Check that 2 {@link Object}s are equals. + * Check that 2 longs are equals. * * @param errorMessage * the error message to display if they differ @@ -173,7 +173,7 @@ abstract public class TestCase { } /** - * Check that 2 {@link Object}s are equals. + * Check that 2 booleans are equals. * * @param expected * the expected value @@ -189,7 +189,7 @@ abstract public class TestCase { } /** - * Check that 2 {@link Object}s are equals. + * Check that 2 booleans are equals. * * @param errorMessage * the error message to display if they differ @@ -208,7 +208,7 @@ abstract public class TestCase { } /** - * Check that 2 {@link Object}s are equals. + * Check that 2 doubles are equals. * * @param expected * the expected value @@ -224,7 +224,7 @@ abstract public class TestCase { } /** - * Check that 2 {@link Object}s are equals. + * Check that 2 doubles are equals. * * @param errorMessage * the error message to display if they differ @@ -242,6 +242,55 @@ abstract public class TestCase { Double.valueOf(actual)); } + /** + * Check that 2 {@link List}s are equals. + * + * @param errorMessage + * the error message to display if they differ + * @param expected + * the expected value + * @param actual + * the actual value + * + * @throws AssertException + * in case they differ + */ + public void assertEquals(List expected, List actual) + throws AssertException { + assertEquals("Assertion failed", expected, actual); + } + + /** + * Check that 2 {@link List}s are equals. + * + * @param errorMessage + * the error message to display if they differ + * @param expected + * the expected value + * @param actual + * the actual value + * @param errorMessage + * the error message to display if they differ + * + * @throws AssertException + * in case they differ + */ + public void assertEquals(String errorMessage, List expected, + List actual) throws AssertException { + + if (expected.size() != actual.size()) { + assertEquals(errorMessage + ": not same number of items", + list(expected), list(actual)); + } + + int size = expected.size(); + for (int i = 0; i < size; i++) { + assertEquals(errorMessage + ": item " + i + + " (0-based) is not correct", expected.get(i), + actual.get(i)); + } + } + /** * Check that given {@link Object} is not NULL. * @@ -286,4 +335,25 @@ abstract public class TestCase { + "Expected value: [%s]%n" // + "Actual value: [%s]", expected, actual); } + + private static String list(List items) { + StringBuilder builder = new StringBuilder(); + for (Object item : items) { + if (builder.length() == 0) { + builder.append(items.size() + " item(s): "); + } else { + builder.append(", "); + } + + builder.append("" + item); + + if (builder.length() > 60) { + builder.setLength(57); + builder.append("..."); + break; + } + } + + return builder.toString(); + } }