CCM NG: improved test coverage of AssertTest.java

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@3517 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
konermann 2015-07-03 09:27:02 +00:00
parent 2302b3928d
commit a423f2db84
1 changed files with 129 additions and 24 deletions

View File

@ -35,38 +35,48 @@ import static org.junit.Assert.*;
*/ */
@Category(UnitTest.class) @Category(UnitTest.class)
public class AssertTest { public class AssertTest {
public AssertTest() { public AssertTest() {
} }
@BeforeClass @BeforeClass
public static void setUpClass() { public static void setUpClass() {
} }
@AfterClass @AfterClass
public static void tearDownClass() { public static void tearDownClass() {
} }
@Before @Before
public void setUp() { public void setUp() {
} }
@After @After
public void tearDown() { public void tearDown() {
} }
@Test(expected = AssertionError.class)
public void checkFailMessage() {
Assert.fail("errormessage");
}
@Test(expected = AssertionError.class)
public void checkFail() {
Assert.fail();
}
/** /**
* Check if {@link Assert#setEnabled(boolean)} works correctly. * Check if {@link Assert#setEnabled(boolean)} works correctly.
*/ */
@Test @Test
public void assertDisable() { public void assertDisable() {
Assert.setEnabled(false); Assert.setEnabled(false);
assertThat(Assert.isEnabled(), is(false)); assertThat(Assert.isEnabled(), is(false));
Assert.setEnabled(true); Assert.setEnabled(true);
} }
/** /**
* Check if {@link Assert#isTrue(boolean)} fails if condition evaluates to * Check if {@link Assert#isTrue(boolean)} fails if condition evaluates to
* {@code false}. * {@code false}.
@ -75,83 +85,178 @@ public class AssertTest {
public void checkIfIsTrueFails() { public void checkIfIsTrueFails() {
Assert.isTrue(false); Assert.isTrue(false);
} }
/** /**
* Check if {@link Assert#isTrue(boolean, java.lang.String)} fails if * Check if {@link Assert#isTrue(boolean, java.lang.String)} succeeds if
* condition evaluates to {@code true}.
*/
@Test
public void checkIsTrue() {
Assert.isTrue(true);
}
/**
* Check if {@link Assert#isTrue(boolean, java.lang.String)} fails if
* condition evaluates to {@code false}. * condition evaluates to {@code false}.
*/ */
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfIsTrueWithMessageFails() { public void checkIfIsTrueWithMessageFails() {
Assert.isTrue(false, "Expected true"); Assert.isTrue(false, "Expected true");
} }
/**
* Check if {@link Assert#isTrue(boolean, java.lang.String)} succeeds if
* condition evaluates to {@code true}.
*/
@Test
public void checkIsTrueWithMessage() {
Assert.isTrue(true, "Expected true");
}
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfIsFalseFails() { public void checkIfIsFalseFails() {
Assert.isFalse(true); Assert.isFalse(true);
} }
@Test
public void checkIsFalse() {
Assert.isFalse(false);
}
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfIsFalseWithMessageFails() { public void checkIfIsFalseWithMessageFails() {
Assert.isFalse(true, "Expected false"); Assert.isFalse(true, "Expected false");
} }
@Test
public void checkIsFalseWithMessage() {
Assert.isFalse(false, "Expected true");
}
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfExistsFailsForNull() { public void checkIfExistsFailsForNull() {
Assert.exists(null); Assert.exists(null);
} }
@Test @Test
public void checkExists() { public void checkExists() {
Assert.exists("foo"); Assert.exists("foo");
} }
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfExistsWithClassFailsForNull() { public void checkIfExistsWithClassFailsForNull() {
Assert.exists(null, Object.class); Assert.exists(null, Object.class);
} }
@Test
public void checkExistsWithClass() {
Assert.exists("foo", Object.class);
}
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfExistsFailsForNullWithMessage() { public void checkIfExistsFailsForNullWithMessage() {
Assert.exists(null, "None null object extected"); Assert.exists(null, "None null object expected");
} }
@Test
public void checkExistsWithLabel() {
Assert.exists("foo", "label");
}
@Test
public void checkExistsWithEmptyLabel() {
Assert.exists("foo", "");
}
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfIsLockedFails() { public void checkIfIsLockedFails() {
final Lockable unlocked = new LockableImpl(); final Lockable unlocked = new LockableImpl();
Assert.isLocked(unlocked); Assert.isLocked(unlocked);
} }
@Test
public void checkIfIsLockedDoesntThrowError() {
Assert.isLocked(null);
}
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfIsUnLockedFails() { public void checkIfIsUnLockedFails() {
final Lockable locked = new LockableImpl(); final Lockable locked = new LockableImpl();
locked.lock(); locked.lock();
Assert.isUnlocked(locked); Assert.isUnlocked(locked);
} }
@Test
public void checkIfIsUnLockedDoesntThrowError() {
Assert.isUnlocked(null);
}
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfIsEqualFailsForUnequalObjects() { public void checkIfIsEqualFailsForUnequalObjects() {
Assert.isEqual("foo", "bar"); Assert.isEqual("foo", "bar");
} }
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfIsEqualFailsForNullAndObject() { public void checkIfIsEqualFailsForNullAndObject() {
Assert.isEqual(null, "bar"); Assert.isEqual(null, "bar");
} }
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfIsEqualFailsForObjectAndNull() { public void checkIfIsEqualFailsForObjectAndNull() {
Assert.isEqual("foo", null); Assert.isEqual("foo", null);
} }
@Test(expected = AssertionError.class)
public void checkIfIsEqualFailsForObjectAndNullWithMessage() {
Assert.isEqual("foo", null, "second object is null");
}
@Test(expected = AssertionError.class)
public void checkIfIsEqualFailsForNullAndObjectWithMessage() {
Assert.isEqual(null, "foo", "first object is null");
}
@Test(expected = AssertionError.class)
public void checkIfIsEqualFailsForUnequalObjectsWithMessage() {
Assert.isEqual("foo", "bar", "unequal ");
}
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfIsNotEqualFailsForEqualObjects() { public void checkIfIsNotEqualFailsForEqualObjects() {
Assert.isNotEqual("foo", "foo"); Assert.isNotEqual("foo", "foo");
} }
@Test(expected = AssertionError.class) @Test(expected = AssertionError.class)
public void checkIfIsNotEqualFailsIfBothAreNull() { public void checkIfIsNotEqualFailsIfBothAreNull() {
Assert.isNotEqual(null, null); Assert.isNotEqual(null, null);
} }
@Test(expected = AssertionError.class)
public void checkIfAssertEqualsFailsIfObjectIsNull() {
Assert.assertEquals(null, "bar", "expectedLabel", "actualLabel");
}
@Test(expected = AssertionError.class)
public void checkIfAssertEqualsFails() {
Assert.assertEquals("foo", "bar", "expectedLabel", "actualLabel");
}
@Test
public void checkAssertEqualsIfNotEnabled() {
Assert.setEnabled(false);
Assert.assertEquals("foo", "bar", "expectedLabel", "actualLabel");
Assert.setEnabled(true);
}
@Test
public void checkAssertEqualsIfBothNull() {
Assert.assertEquals(null, null, "expectedLabel", "actualLabel");
}
@Test
public void checkAssertEqualsWithEqualObjects() {
Assert.assertEquals("foo", "foo", "expectedLabel", "actualLabel");
}
} }