/* ITI 1121. Introduction to Computing II; Winter 2010; Laboratory 2 * ITI 1521. Introduction à l'informatique II; Hiver 2010; Laboratoire 2 */ /** A series of tests for the method findAndReplace. * * @author Marcel Turcotte (turcotte@site.uottawa.ca) */ import junit.framework.Assert; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; public class TestFindAndReplace extends TestCase { public static void testInIsNull() { String[] query = { "I" }; String[] replacement = { "You" }; Assert.assertNull( Utils.findAndReplace( null, query, replacement ) ); } public static void testQueryIsNull() { String[] text = { "I", "understand" }; String[] replacement = { "You" }; Assert.assertNull( Utils.findAndReplace( text, null, replacement ) ); } public static void testReplacementIsNull() { String[] text = { "I", "understand" }; String[] query = { "I" }; Assert.assertNull( Utils.findAndReplace( text, query, null ) ); } public static void testInAndQueryAreNull() { String[] replacement = { "You" }; Assert.assertNull( Utils.findAndReplace( null, null, replacement ) ); } public static void testInAndReplacementreNull() { String[] query = { "I" }; Assert.assertNull( Utils.findAndReplace( null, query, null ) ); } public static void testQueryAndReplacementreNull() { String[] text = { "I", "understand" }; Assert.assertNull( Utils.findAndReplace( text, null, null ) ); } public static void testAllNull() { Assert.assertNull( Utils.findAndReplace( null, null, null ) ); } public static void testNotSameLength() { String[] text = { "I", "understand" }; String[] query = { "I" }; String[] replacement = { "You", "They" }; Assert.assertNull( Utils.findAndReplace( text, query, replacement ) ); } public static void testNullInIn() { String[] text = { "I", null }; String[] query = { "I" }; String[] replacement = { "You" }; Assert.assertNull( Utils.findAndReplace( text, query, replacement ) ); } public static void testNullInQuery() { String[] text = { "I", "understand" }; String[] query = { "I", null }; String[] replacement = { "You", "They" }; Assert.assertNull( Utils.findAndReplace( text, query, replacement ) ); } public static void testNullInReplacement() { String[] text = { "I", "understand" }; String[] query = { "I", "We" }; String[] replacement = { null, "They" }; Assert.assertNull( Utils.findAndReplace( text, query, replacement ) ); } public static void testNoChange1() { String[] text = { "I", "understand" }; String[] query = { }; String[] replacement = { }; String[] result = Utils.findAndReplace( text, query, replacement ); Assert.assertNotNull( result ); Assert.assertFalse( text == result ); Assert.assertTrue( text.length == result.length ); for ( int i=0; i