lundi 15 août 2016

JUinit4 - Test if method does nothing

How can I test if a method does nothing. For example I have a static method that throws an exception if the given string-argument is null or empty (it's meant for argument-validation). Right now my tests look like this:

@Test
public void notNullOrEmpty_doesNothingIfValueIsNotNullOrEmpty() {
    Require.notNullOrEmpty(Generate.randomString());
    assertTrue(true); // <- this looks very ugly
}

@Test(expected = IllegalArgumentException.class)
public void notNullOrEmpty_throwsExceptionIfValueIsNull() {
    Require.notNullOrEmpty(null);
}

@Test
public void notNullOrEmpty_throwsExceptionIfValueIsEmpty() {
    Require.notNullOrEmpty("");
}

How can I make the first test to pass without calling assertTrue(true), there is a Assert.fail() is there something like an Assert.pass()?

Aucun commentaire:

Enregistrer un commentaire