1 21 package org.dbunit.dataset; 22 23 import junit.framework.TestCase; 24 25 import java.util.Arrays ; 26 import java.util.List ; 27 28 33 public class AbstractTest extends TestCase 34 { 35 private static final String [] TABLE_NAMES = { 36 "TEST_TABLE", 37 "SECOND_TABLE", 38 "EMPTY_TABLE", 39 "PK_TABLE", 40 "ONLY_PK_TABLE", 41 "EMPTY_MULTITYPE_TABLE", 42 }; 43 private static final String [] DUPLICATE_TABLE_NAMES = { 44 "DUPLICATE_TABLE", 45 "EMPTY_TABLE", 46 "DUPLICATE_TABLE", 47 }; 48 private static final String EXTRA_TABLE_NAME = "EXTRA_TABLE"; 49 50 public AbstractTest(String s) 51 { 52 super(s); 53 } 54 55 protected String [] getExpectedNames() throws Exception 56 { 57 return (String [])AbstractTest.TABLE_NAMES.clone(); 58 } 59 60 protected String [] getExpectedLowerNames() throws Exception 61 { 62 String [] names = (String [])AbstractTest.TABLE_NAMES.clone(); 63 for (int i = 0; i < names.length; i++) 64 { 65 names[i] = names[i].toLowerCase(); 66 } 67 68 return names; 69 } 70 71 protected String [] getExpectedDuplicateNames() 72 { 73 return (String [])AbstractTest.DUPLICATE_TABLE_NAMES.clone(); 74 } 75 76 protected String getDuplicateTableName() 77 { 78 return "DUPLICATE_TABLE"; 79 } 80 81 public String getExtraTableName() 82 { 83 return AbstractTest.EXTRA_TABLE_NAME; 84 } 85 86 public void assertEqualsIgnoreCase(String message, String expected, String actual) 87 { 88 if (!expected.equalsIgnoreCase(actual)) 89 { 90 assertEquals(message, expected, actual); 91 } 92 } 93 94 public void assertContains(String message, Object [] expected, Object [] actual) 95 { 96 List expectedList = Arrays.asList(expected); 97 List actualList = Arrays.asList(actual); 98 99 if (!actualList.containsAll(expectedList)) 100 { 101 fail(message + " expected contains:<" + expectedList + "> but was:<" 102 + actualList + ">"); 103 } 104 } 105 106 public void assertContainsIgnoreCase(String message, String [] expected, String [] actual) 107 { 108 String [] expectedLowerCase = new String [expected.length]; 109 for (int i = 0; i < expected.length; i++) 110 { 111 expectedLowerCase[i] = expected[i].toLowerCase(); 112 } 113 114 String [] actualLowerCase = new String [actual.length]; 115 for (int i = 0; i < actual.length; i++) 116 { 117 actualLowerCase[i] = actual[i].toLowerCase(); 118 } 119 120 assertContains(message, expectedLowerCase, actualLowerCase); 121 } 122 123 } 124 | Popular Tags |