X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Ftest%2FAssertionUtils.java;h=8c25fc13f6963646653ee3cab510c6d622899b2e;hb=96c8961955a306314dfe0cf9ca192252de39fc1c;hp=966a52e4f4318a9f00d7ad9977f131e5f6c5a84c;hpb=f4d446b84fa1a38ed83cd157f79fdb8233822145;p=utils diff --git a/support/general/src/test/java/org/wamblee/test/AssertionUtils.java b/support/general/src/test/java/org/wamblee/test/AssertionUtils.java index 966a52e4..8c25fc13 100644 --- a/support/general/src/test/java/org/wamblee/test/AssertionUtils.java +++ b/support/general/src/test/java/org/wamblee/test/AssertionUtils.java @@ -1,34 +1,33 @@ /* - * Copyright 2006 the original author or authors. - * + * Copyright 2005-2010 the original author or authors. + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.test; -import junit.framework.TestCase; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import java.util.Arrays; -import java.util.Iterator; import java.util.Map; import java.util.Set; +import java.util.Map.Entry; + +import junit.framework.TestCase; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * Useful assertions for use in test cases. - * + * * @author Erik Brakkee */ public final class AssertionUtils { @@ -36,7 +35,7 @@ public final class AssertionUtils { /** * Disabled constructor. - * + * */ private AssertionUtils() { // Empty @@ -44,7 +43,7 @@ public final class AssertionUtils { /** * Asserts that two object arrays are equal. - * + * * @param aExpected * Expected object array. * @param aActual @@ -56,7 +55,7 @@ public final class AssertionUtils { /** * Asserts that two object arrays are equal. - * + * * @param aMsg * Message. * @param aExpected @@ -75,7 +74,7 @@ public final class AssertionUtils { } } - /** +/** * Asserts that two objects are equal, and in case the object is an Object[] * delegates to {@link #assertEquals(String, Object[], Object[]). * @@ -100,7 +99,7 @@ public final class AssertionUtils { /** * Asserts that two maps are equal by comparing all keys and by checking * that the values for the same keys are the same. - * + * * @param aMsg * Message. * @param aExpectedMap @@ -110,25 +109,28 @@ public final class AssertionUtils { */ public static void assertEquals(String aMsg, Map aExpectedMap, Map aActual) { - TestCase.assertEquals("Map sizes differ", aExpectedMap.size(), - aActual.size()); + TestCase.assertEquals("Map sizes differ", aExpectedMap.size(), aActual + .size()); - Set keys = aExpectedMap.keySet(); + Set> expectedEntries = aExpectedMap.entrySet(); - for (Iterator i = keys.iterator(); i.hasNext();) { - String key = (String) i.next(); + for (Entry entry: expectedEntries) { + Key key = entry.getKey(); TestCase.assertTrue("Map does not containg entry for key:" + key, aActual.containsKey(key)); AssertionUtils.assertEquals("Value of key " + key + " of map", - aExpectedMap.get(key), aActual.get(key)); + entry.getValue(), aActual.get(key)); } } /** * Asserts that an exception occurs. - * @param aRunnable Test cases should create a subclass of this which contains the - * code that should throw an exception. - * @param aType Type of exception that is expected. + * + * @param aRunnable + * Test cases should create a subclass of this which contains the + * code that should throw an exception. + * @param aType + * Type of exception that is expected. */ public static void assertException(ErroneousCode aObject, Class aType) { try { @@ -138,7 +140,7 @@ public final class AssertionUtils { if (aType.isInstance(t)) { LOG.info("Expected exception occured " + t.getMessage()); - return; // ok + return; // ok } else { throw new RuntimeException(t); }