Permalink
Browse files

Example tests to make it explicitly clear that common types such as

Strings and primitives also work.
Specific primitives tested are: int, double, char
Specific common types tested are: String, BigDecimal
  • Loading branch information...
1 parent e1581fc commit 5ee6961fdce38501200ce6b5739f219a7cc99400 Alan Escreet committed May 19, 2011
Showing with 160 additions and 2 deletions.
  1. +160 −2 src/test/java/org/junit/tests/assertion/AssertionTest.java
@@ -509,6 +509,11 @@ public int compareTo(ComparableStub o) {
public boolean equals(Object o) {
return this.equalsReturnValue;
}
+
+ @Override
+ public String toString() {
+ return String.valueOf(this.compareToReturnValue);
+ }
}
private static final ComparableStub NULL_VALUE = null;
@@ -522,8 +527,11 @@ public void assertLessThanFailsWithSelfExplanatoryMessage() {
try {
assertLessThan(REFERENCE_VALUE, REFERENCE_VALUE);
} catch (AssertionError e) {
- assertEquals("Expected less than: java.math.BigDecimal<" + REFERENCE_VALUE
- + "> but was: java.math.BigDecimal<" + REFERENCE_VALUE + '>', e.getMessage());
+ assertEquals(
+ "Expected less than: " + ComparableStub.class.getName()
+ + '<' + REFERENCE_VALUE + "> but was: "
+ + ComparableStub.class.getName() + '<'
+ + REFERENCE_VALUE + '>', e.getMessage());
}
}
@@ -606,4 +614,154 @@ public void assertEquivalentShouldFailWhenActualLessThanReference() {
public void assertEquivalentShouldFailWhenActualGreaterThanReference() {
assertEquivalent(REFERENCE_VALUE, HIGHER_VALUE);
}
+
+ @Test
+ public void assertLessThanShouldPassWithAutoboxedInt() {
+ assertLessThan(0, -1);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertLessThanShouldFailWithAutoboxedInt() {
+ assertLessThan(0, 0);
+ }
+
+ @Test
+ public void assertGreaterThanShouldPassWithAutoboxedInt() {
+ assertGreaterThan(0, 1);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertGreaterThanShouldFailWithAutoboxedInt() {
+ assertGreaterThan(0, 0);
+ }
+
+ @Test
+ public void assertEquivalentShouldPassWithAutoboxedInt() {
+ assertEquivalent(0, 0);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertEquivalentThanShouldFailWithAutoboxedInt() {
+ assertEquivalent(0, 1);
+ }
+
+ @Test
+ public void assertLessThanShouldPassWithAutoboxedDouble() {
+ assertLessThan(0.0, -1.0);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertLessThanShouldFailWithAutoboxedDouble() {
+ assertLessThan(0.0, 0.0);
+ }
+
+ @Test
+ public void assertGreaterThanShouldPassWithAutoboxedDouble() {
+ assertGreaterThan(0.0, 1.0);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertGreaterThanShouldFailWithAutoboxedDouble() {
+ assertGreaterThan(0.0, 0.0);
+ }
+
+ @Test
+ public void assertEquivalentShouldPassWithAutoboxedDouble() {
+ assertEquivalent(0.0, 0.0);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertEquivalentThanShouldFailWithAutoboxedDouble() {
+ assertEquivalent(0.0, 1.0);
+ }
+
+ @Test
+ public void assertLessThanShouldPassWithString() {
+ assertLessThan("b", "a");
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertLessThanShouldFailWithString() {
+ assertLessThan("b", "b");
+ }
+
+ @Test
+ public void assertGreaterThanShouldPassWithString() {
+ assertGreaterThan("b", "c");
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertGreaterThanShouldFailWithString() {
+ assertGreaterThan("b", "b");
+ }
+
+ @Test
+ public void assertEquivalentShouldPassWithString() {
+ assertEquivalent("b", "b");
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertEquivalentThanShouldFailWithString() {
+ assertEquivalent("b", "a");
+ }
+
+ @Test
+ public void assertLessThanShouldPassWithAutoboxedChar() {
+ assertLessThan('b', 'a');
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertLessThanShouldFailWithAutoboxedChar() {
+ assertLessThan('b', 'b');
+ }
+
+ @Test
+ public void assertGreaterThanShouldPassWithAutoboxedChar() {
+ assertGreaterThan('b', 'c');
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertGreaterThanShouldFailWithAutoboxedChar() {
+ assertGreaterThan('b', 'b');
+ }
+
+ @Test
+ public void assertEquivalentShouldPassWithAutoboxedChar() {
+ assertEquivalent('b', 'b');
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertEquivalentThanShouldFailWithAutoboxedChar() {
+ assertEquivalent('b', 'a');
+ }
+
+ @Test
+ public void assertLessThanShouldPassWithBigDecimal() {
+ assertLessThan(BigDecimal.ONE, BigDecimal.ZERO);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertLessThanShouldFailWithBigDecimal() {
+ assertLessThan(BigDecimal.ZERO, BigDecimal.ZERO);
+ }
+
+ @Test
+ public void assertGreaterThanShouldPassWithBigDecimal() {
+ assertGreaterThan(BigDecimal.ZERO, BigDecimal.ONE);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertGreaterThanShouldFailWithBigDecimal() {
+ assertGreaterThan(BigDecimal.ZERO, BigDecimal.ZERO);
+ }
+
+ @Test
+ public void assertEquivalentShouldPassWithBigDecimal() {
+ assertEquivalent(BigDecimal.ZERO, BigDecimal.ZERO);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void assertEquivalentThanShouldFailWithBigDecimal() {
+ assertEquivalent(BigDecimal.ZERO, BigDecimal.ONE);
+ }
}

0 comments on commit 5ee6961

Please sign in to comment.