From: Juergen H. <jho...@us...> - 2008-11-27 18:04:42
|
Update of /cvsroot/springframework/spring/mock/org/springframework/test/web In directory fdv4jf1.ch3.sourceforge.com:/tmp/cvs-serv4919/mock/org/springframework/test/web Modified Files: ModelAndViewAssert.java AbstractModelAndViewTests.java Log Message: polishing Index: ModelAndViewAssert.java =================================================================== RCS file: /cvsroot/springframework/spring/mock/org/springframework/test/web/ModelAndViewAssert.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ModelAndViewAssert.java 10 Sep 2007 13:26:40 -0000 1.3 --- ModelAndViewAssert.java 27 Nov 2008 18:04:36 -0000 1.4 *************** *** 1,4 **** /* ! * Copyright 2002-2007 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); --- 1,4 ---- /* ! * Copyright 2002-2008 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); *************** *** 28,40 **** /** - * <p> * A collection of assertions intended to simplify testing scenarios * dealing with Spring Web MVC * {@link org.springframework.web.servlet.ModelAndView ModelAndView} objects. ! * Intended for use with JUnit 4 and TestNG. ! * </p> ! * <p> * All <code>assert*()</code> methods throw {@link AssertionError}s. - * </p> * * @author Sam Brannen --- 28,37 ---- /** * A collection of assertions intended to simplify testing scenarios * dealing with Spring Web MVC * {@link org.springframework.web.servlet.ModelAndView ModelAndView} objects. ! * ! * <p>Intended for use with JUnit 4 and TestNG. * All <code>assert*()</code> methods throw {@link AssertionError}s. * * @author Sam Brannen *************** *** 50,54 **** * exists and checks it type, based on the <code>expectedType</code>. If * the model entry exists and the type matches, the model value is returned. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param modelName name of the object to add to the model (never --- 47,50 ---- *************** *** 62,70 **** assertCondition(mav != null, "ModelAndView is null"); assertCondition(mav.getModel() != null, "Model is null"); ! final Object obj = mav.getModel().get(modelName); assertCondition(obj != null, "Model attribute with name '" + modelName + "' is null"); ! assertCondition(expectedType.isAssignableFrom(obj.getClass()), "Model attribute is not of expected type '" ! + expectedType.getName() + "' but rather of type '" + obj.getClass().getName() + "'"); return obj; } --- 58,66 ---- assertCondition(mav != null, "ModelAndView is null"); assertCondition(mav.getModel() != null, "Model is null"); ! Object obj = mav.getModel().get(modelName); assertCondition(obj != null, "Model attribute with name '" + modelName + "' is null"); ! assertCondition(expectedType.isAssignableFrom(obj.getClass()), "Model attribute is not of expected type '" + ! expectedType.getName() + "' but rather of type '" + obj.getClass().getName() + "'"); return obj; } *************** *** 72,76 **** /** * Compare each individual entry in a list, without first sorting the lists. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param modelName name of the object to add to the model (never --- 68,71 ---- *************** *** 91,95 **** /** * Assert whether or not a model attribute is available. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param modelName name of the object to add to the model (never --- 86,89 ---- *************** *** 97,101 **** */ public static void assertModelAttributeAvailable(ModelAndView mav, Object modelName) throws AssertionError { - assertCondition(mav != null, "ModelAndView is null"); assertCondition(mav.getModel() != null, "Model is null"); --- 91,94 ---- *************** *** 107,111 **** * Compare a given <code>expectedValue</code> to the value from the model * bound under the given <code>modelName</code>. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param modelName name of the object to add to the model (never --- 100,103 ---- *************** *** 125,134 **** * Inspect the <code>expectedModel</code> to see if all elements in the * model appear and are equal. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param expectedModel the expected model */ public static void assertModelAttributeValues(ModelAndView mav, Map expectedModel) throws AssertionError { - assertCondition(mav != null, "ModelAndView is null"); assertCondition(mav.getModel() != null, "Model is null"); --- 117,124 ---- *************** *** 161,165 **** * Compare each individual entry in a list after having sorted both lists * (optionally using a comparator). - * * @param mav ModelAndView to test against (never <code>null</code>) * @param modelName name of the object to add to the model (never --- 151,154 ---- *************** *** 195,204 **** * Check to see if the view name in the ModelAndView matches the given * <code>expectedName</code>. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param expectedName the name of the model value */ public static void assertViewName(ModelAndView mav, String expectedName) throws AssertionError { - assertCondition(mav != null, "ModelAndView is null"); assertCondition(expectedName.equals(mav.getViewName()), "View name is not equal to '" + expectedName --- 184,191 ---- *************** *** 210,219 **** * Fails by throwing an <code>AssertionError</code> with the supplied * <code>message</code>. - * * @param message the exception message to use * @see #assertCondition(boolean,String) */ private static void fail(String message) throws AssertionError { - throw new AssertionError(message); } --- 197,204 ---- *************** *** 223,227 **** * <code>AssertionError</code> with the supplied <code>message</code> if * the test result is <code>false</code>. - * * @param condition a boolean expression * @param message the exception message to use if the assertion fails --- 208,211 ---- *************** *** 230,234 **** */ private static void assertCondition(boolean condition, String message) throws AssertionError { - if (!condition) { fail(message); --- 214,217 ---- *************** *** 237,241 **** private static void appendNonMatchingSetsErrorMessage(Set assertionSet, Set incorrectSet, StringBuffer buf) { - Set tempSet = new HashSet(); tempSet.addAll(incorrectSet); --- 220,223 ---- Index: AbstractModelAndViewTests.java =================================================================== RCS file: /cvsroot/springframework/spring/mock/org/springframework/test/web/AbstractModelAndViewTests.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AbstractModelAndViewTests.java 8 Sep 2007 15:16:48 -0000 1.5 --- AbstractModelAndViewTests.java 27 Nov 2008 18:04:36 -0000 1.6 *************** *** 27,40 **** /** - * <p> * Convenient JUnit 3.8 base class for tests dealing with Spring Web MVC * {@link org.springframework.web.servlet.ModelAndView ModelAndView} objects. ! * </p> ! * <p> ! * All <code>assert*()</code> methods throw {@link AssertionFailedError}s. ! * </p> ! * <p> ! * Consider the use of {@link ModelAndViewAssert} with JUnit 4 and TestNG. ! * </p> * * @author Alef Arendsen --- 27,36 ---- /** * Convenient JUnit 3.8 base class for tests dealing with Spring Web MVC * {@link org.springframework.web.servlet.ModelAndView ModelAndView} objects. ! * ! * <p>All <code>assert*()</code> methods throw {@link AssertionFailedError}s. ! * ! * <p>Consider the use of {@link ModelAndViewAssert} with JUnit 4 and TestNG. * * @author Alef Arendsen *************** *** 51,55 **** * exists and checks it type, based on the <code>expectedType</code>. If * the model entry exists and the type matches, the model value is returned. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param modelName name of the object to add to the model (never --- 47,50 ---- *************** *** 59,63 **** */ protected Object assertAndReturnModelAttributeOfType(ModelAndView mav, Object modelName, Class expectedType) { - try { return ModelAndViewAssert.assertAndReturnModelAttributeOfType(mav, modelName, expectedType); --- 54,57 ---- *************** *** 70,74 **** /** * Compare each individual entry in a list, without first sorting the lists. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param modelName name of the object to add to the model (never --- 64,67 ---- *************** *** 77,81 **** */ protected void assertCompareListModelAttribute(ModelAndView mav, Object modelName, List expectedList) { - try { ModelAndViewAssert.assertCompareListModelAttribute(mav, modelName, expectedList); --- 70,73 ---- *************** *** 88,92 **** /** * Assert whether or not a model attribute is available. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param modelName name of the object to add to the model (never --- 80,83 ---- *************** *** 94,98 **** */ protected void assertModelAttributeAvailable(ModelAndView mav, Object modelName) { - try { ModelAndViewAssert.assertModelAttributeAvailable(mav, modelName); --- 85,88 ---- *************** *** 106,110 **** * Compare a given <code>expectedValue</code> to the value from the model * bound under the given <code>modelName</code>. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param modelName name of the object to add to the model (never --- 96,99 ---- *************** *** 113,117 **** */ protected void assertModelAttributeValue(ModelAndView mav, Object modelName, Object expectedValue) { - try { ModelAndViewAssert.assertModelAttributeValue(mav, modelName, expectedValue); --- 102,105 ---- *************** *** 125,134 **** * Inspect the <code>expectedModel</code> to see if all elements in the * model appear and are equal. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param expectedModel the expected model */ protected void assertModelAttributeValues(ModelAndView mav, Map expectedModel) { - try { ModelAndViewAssert.assertModelAttributeValues(mav, expectedModel); --- 113,120 ---- *************** *** 142,146 **** * Compare each individual entry in a list after having sorted both lists * (optionally using a comparator). - * * @param mav ModelAndView to test against (never <code>null</code>) * @param modelName name of the object to add to the model (never --- 128,131 ---- *************** *** 153,157 **** protected void assertSortAndCompareListModelAttribute( ModelAndView mav, Object modelName, List expectedList, Comparator comparator) { - try { ModelAndViewAssert.assertSortAndCompareListModelAttribute(mav, modelName, expectedList, comparator); --- 138,141 ---- *************** *** 165,174 **** * Check to see if the view name in the ModelAndView matches the given * <code>expectedName</code>. - * * @param mav ModelAndView to test against (never <code>null</code>) * @param expectedName the name of the model value */ protected void assertViewName(ModelAndView mav, String expectedName) { - try { ModelAndViewAssert.assertViewName(mav, expectedName); --- 149,156 ---- |