1 54 55 package junitx.framework; 56 57 63 public class ComparableAssert { 64 65 68 private ComparableAssert() { 69 } 70 71 76 static public void assertLesser(String message, 77 Comparable limit, 78 Comparable actual) { 79 Assert.assertNotNull(message, limit); 80 Assert.assertNotNull(message, actual); 81 if (limit.compareTo(actual) <= 0) { 82 failLesser(message, limit, actual); 83 } 84 } 85 86 91 static public void assertLesser(Comparable limit, 92 Comparable actual) { 93 assertLesser(null, limit, actual); 94 } 95 96 101 static public void assertNotLesser(String message, 102 Comparable limit, 103 Comparable actual) { 104 Assert.assertNotNull(message, limit); 105 Assert.assertNotNull(message, actual); 106 if (limit.compareTo(actual) > 0) { 107 failNotLesser(message, limit, actual); 108 } 109 } 110 111 116 static public void assertNotLesser(Comparable limit, 117 Comparable actual) { 118 assertNotLesser(null, limit, actual); 119 } 120 121 126 static public void assertEquals(String message, 127 Comparable expected, 128 Comparable actual) { 129 Assert.assertNotNull(message, expected); 130 Assert.assertNotNull(message, actual); 131 if (expected.compareTo(actual) != 0) { 132 failNotEquals(message, expected, actual); 133 } 134 } 135 136 141 static public void assertEquals(Comparable expected, 142 Comparable actual) { 143 assertEquals(null, expected, actual); 144 } 145 146 151 static public void assertNotEquals(String message, 152 Comparable expected, 153 Comparable actual) { 154 Assert.assertNotNull(message, expected); 155 Assert.assertNotNull(message, actual); 156 if (expected.compareTo(actual) == 0) { 157 failEquals(message, expected); 158 } 159 } 160 161 166 static public void assertNotEquals(Comparable expected, 167 Comparable actual) { 168 assertNotEquals(null, expected, actual); 169 } 170 171 176 static public void assertGreater(String message, 177 Comparable limit, 178 Comparable actual) { 179 Assert.assertNotNull(message, limit); 180 Assert.assertNotNull(message, actual); 181 if (limit.compareTo(actual) >= 0) { 182 failGreater(message, limit, actual); 183 } 184 } 185 186 191 static public void assertGreater(Comparable limit, 192 Comparable actual) { 193 assertGreater(null, limit, actual); 194 } 195 196 201 static public void assertNotGreater(String message, 202 Comparable limit, 203 Comparable actual) { 204 Assert.assertNotNull(message, limit); 205 Assert.assertNotNull(message, actual); 206 if (limit.compareTo(actual) < 0) { 207 failNotGreater(message, limit, actual); 208 } 209 } 210 211 216 static public void assertNotGreater(Comparable limit, 217 Comparable actual) { 218 assertNotGreater(null, limit, actual); 219 } 220 221 static private void failGreater(String message, 222 Object limit, 223 Object actual) { 224 String formatted = ""; 225 if (message != null) { 226 formatted = message + " "; 227 } 228 229 Assert.fail(formatted + "expected greater than:<" + 230 limit + "> but was:<" + actual + ">"); 231 } 232 233 static private void failNotGreater(String message, 234 Object limit, 235 Object actual) { 236 String formatted = ""; 237 if (message != null) { 238 formatted = message + " "; 239 } 240 241 Assert.fail(formatted + "expected not greater than:<" + 242 limit + "> but was:<" + actual + ">"); 243 } 244 245 static private void failLesser(String message, 246 Object limit, 247 Object actual) { 248 String formatted = ""; 249 if (message != null) { 250 formatted = message + " "; 251 } 252 253 Assert.fail(formatted + "expected lesser than:<" + 254 limit + "> but was:<" + actual + ">"); 255 } 256 257 static private void failNotLesser(String message, 258 Object limit, 259 Object actual) { 260 String formatted = ""; 261 if (message != null) { 262 formatted = message + " "; 263 } 264 265 Assert.fail(formatted + "expected not lesser than:<" + 266 limit + "> but was:<" + actual + ">"); 267 } 268 269 static private void failNotEquals(String message, 270 Object expected, 271 Object actual) { 272 String formatted = ""; 273 if (message != null) { 274 formatted = message + " "; 275 } 276 277 Assert.fail(formatted + "expected equals to:<" + 278 expected + "> but was:<" + actual + ">"); 279 } 280 281 static private void failEquals(String message, 282 Object expected) { 283 String formatted = ""; 284 if (message != null) { 285 formatted = message + " "; 286 } 287 288 Assert.fail(formatted + "expected not equals to:<" + 289 expected + ">"); 290 } 291 292 } 293 | Popular Tags |