you could do it passing flag (shouldThrowException) as one of the test parameters. but much cleaner way would be to make two tests. one for correct parameters and one for bad parameters. i would do this:
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.runner.RunWith;
import com.googlecode.zohhak.api.Coercion;
import com.googlecode.zohhak.api.TestWith;
import com.googlecode.zohhak.api.runners.ZohhakRunner;
@RunWith(ZohhakRunner.class)
public class MyTest {
@TestWith({
"parameter1, parameter2",
"otherParameter1, otherParameter2"
})
public void should_construct_project(Parameter parameter1, Parameter parameter2) {
new Project(parameter1, parameter2);
}
@TestWith({
"null, parameter2",
"otherParameter1, null",
"badParameter1, goodParameter2"
})
public void should_fail_constructing_project(Parameter parameter1, Parameter parameter2) {
assertThatThrownBy(() -> new Project(parameter1, parameter2))
.isInstanceOf(NullPointerException.class);
}
@Coercion
public Parameter toParameter(String input) {
return new Parameter(...);
}
}
in case you want to test all possible parameters combinations then data-providers or theories could be useful.