1 6 7 package de.tivano.junit; 8 9 import java.io.File ; 10 import java.lang.reflect.Field ; 11 import java.util.Properties ; 12 13 import junit.framework.TestCase; 14 15 22 public class ParametrizationTestDummy extends TestCase { 23 24 private Properties expectedData; 25 private String keyPrefix; 26 27 public boolean fieldBoolean; 28 public char fieldChar; 29 public byte fieldByte; 30 public short fieldShort; 31 public int fieldInt; 32 public long fieldLong; 33 public float fieldFloat; 34 public double fieldDouble; 35 public String fieldString; 36 public File fieldFile; 37 38 public Boolean fieldBooleanObj; 39 public Character fieldCharObj; 40 public Byte fieldByteObj; 41 public Short fieldShortObj; 42 public Integer fieldIntObj; 43 public Long fieldLongObj; 44 public Float fieldFloatObj; 45 public Double fieldDoubleObj; 46 47 private boolean methodBoolean; 48 private char methodChar; 49 private byte methodByte; 50 private short methodShort; 51 private int methodInt; 52 private long methodLong; 53 private float methodFloat; 54 private double methodDouble; 55 private String methodString; 56 private File methodFile; 57 58 private Boolean methodBooleanObj; 59 private Character methodCharObj; 60 private Byte methodByteObj; 61 private Short methodShortObj; 62 private Integer methodIntObj; 63 private Long methodLongObj; 64 private Float methodFloatObj; 65 private Double methodDoubleObj; 66 67 public int special; 72 73 public String leaveMeAlone = "DONT_EVER_CHANGE_THIS_VALUE"; 76 77 78 public ParametrizationTestDummy(String name) { 79 super(name); 80 } 81 82 83 public void setExpectedData(String keyPrefix, Properties expectedData) { 84 this.expectedData = expectedData; 85 this.keyPrefix = keyPrefix; 86 } 87 88 91 public void setMethodBoolean(boolean methodBoolean) { 92 this.methodBoolean = methodBoolean; 93 } 94 95 98 public void setMethodBooleanObj(java.lang.Boolean methodBooleanObj) { 99 this.methodBooleanObj = methodBooleanObj; 100 } 101 102 105 public void setMethodChar(char methodChar) { 106 this.methodChar = methodChar; 107 } 108 109 112 public void setMethodCharObj(java.lang.Character methodCharObj) { 113 this.methodCharObj = methodCharObj; 114 } 115 116 119 public void setMethodDouble(double methodDouble) { 120 this.methodDouble = methodDouble; 121 } 122 123 126 public void setMethodDoubleObj(java.lang.Double methodDoubleObj) { 127 this.methodDoubleObj = methodDoubleObj; 128 } 129 130 133 public void setMethodFile(File methodFile) { 134 this.methodFile = methodFile; 135 } 136 137 140 public void setMethodFloat(float methodFloat) { 141 this.methodFloat = methodFloat; 142 } 143 144 147 public void setMethodFloatObj(java.lang.Float methodFloatObj) { 148 this.methodFloatObj = methodFloatObj; 149 } 150 151 154 public void setMethodInt(int methodInt) { 155 this.methodInt = methodInt; 156 } 157 158 161 public void setMethodIntObj(java.lang.Integer methodIntObj) { 162 this.methodIntObj = methodIntObj; 163 } 164 165 168 public void setMethodLong(long methodLong) { 169 this.methodLong = methodLong; 170 } 171 172 175 public void setMethodLongObj(java.lang.Long methodLongObj) { 176 this.methodLongObj = methodLongObj; 177 } 178 179 182 public void setMethodShort(short methodShort) { 183 this.methodShort = methodShort; 184 } 185 186 189 public void setMethodShortObj(java.lang.Short methodShortObj) { 190 this.methodShortObj = methodShortObj; 191 } 192 193 196 public void setMethodString(java.lang.String methodString) { 197 this.methodString = methodString; 198 } 199 200 204 public void setSpecial(int value) { 205 this.special = -value; 208 } 209 210 213 public void setMethodByteObj(java.lang.Byte methodByteObj) { 214 this.methodByteObj = methodByteObj; 215 } 216 217 220 public void setMethodByte(byte methodByte) { 221 this.methodByte = methodByte; 222 } 223 224 225 public void testStandardData() throws IllegalAccessException { 226 assertNotNull("Expected data not set", expectedData); 228 assertNotNull("Key prefix not set", keyPrefix); 229 Field [] allFields = getClass().getDeclaredFields(); 231 assertEquals("ParametrizationTestDummy.testStandardData(), " + keyPrefix + 234 ": Field count mismatch:", 40, allFields.length); 235 for (int i=0; i<allFields.length; i++) { 236 String name = allFields[i].getName(); 237 if (name.startsWith("field") || name.startsWith("method")) { 238 String value = allFields[i].get(this).toString(); 239 String expected = expectedData.getProperty(keyPrefix + "." + name); 240 assertEquals("ParametrizationTestDummy.testStandardData(), " + keyPrefix + 241 ": Data for property '" + name + "':", expected, value); 242 } 243 } 244 } 245 246 247 public void testSetterMethodAndPublicField() { 248 assertNotNull("ParametrizationTestDummy.testSetterMethodAndPublicField(): Expected data not set:", expectedData); 250 assertNotNull("ParametrizationTestDummy.testSetterMethodAndPublicField(): Key prefix not set", keyPrefix); 251 int expected = -Integer.parseInt(expectedData.getProperty(keyPrefix + ".special")); 252 assertEquals("ParametrizationTestDummy.testSetterMethodAndPublicField(), " + keyPrefix + ":", 253 expected, special); 254 } 255 256 257 public void testLeaveMeAlone() { 258 assertEquals("ParametrizationTestDummy.testLeaveMeAlone(): ", "DONT_EVER_CHANGE_THIS_VALUE", leaveMeAlone); 259 } 260 261 264 public void testFailAlways() { 265 fail("ParametrizationTestDummy.testFailAlways(): This test is expected to fail"); 266 } 267 } 268 | Popular Tags |