Created
August 27, 2015 06:59
-
-
Save maartenl/73f4b8aad4cd41a83ff1 to your computer and use it in GitHub Desktop.
Testing for Exceptions in the new JUnit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author mrbear | |
*/ | |
public class AddressJUnitTest | |
{ | |
@Rule | |
public ExpectedException nameMayNotBeNull = ExpectedException.none(); | |
@Test | |
public void testWithNullpointerExceptionInJUnit() | |
{ | |
nameMayNotBeNull.expect(NullPointerException.class); | |
nameMayNotBeNull.expectMessage("the name may not be null"); | |
Address mrbear = new Address("Mr. Bear"); | |
mrbear.setName(null); | |
assertThat(mrbear.getName(), not(nullValue())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment