I want to test this constructor with different name parameters.
public Horse(String name, double speed, double distance) {
if (isNull(name)) {
throw new IllegalArgumentException("Name cannot be null.");
} else if (name.isBlank()) {
throw new IllegalArgumentException("Name cannot be blank.");
}
if (speed < 0) {
throw new IllegalArgumentException("Speed cannot be negative.");
}
if (distance < 0) {
throw new IllegalArgumentException("Distance cannot be negative.");
}
this.name = name;
this.speed = speed;
this.distance = distance;
}
public Horse(String name, double speed) {
this(name, speed, 0);
}
this test looks like
@ParameterizedTest
@ValueSource(strings = {" ", "t", " "})
void Constructor_Empty_String_Message(String s){
//given
//when
//then
try{
new Horse(s,0);
} catch (Exception e){
Assertions.assertEquals("Name cannot be blank.",e.toString());
}
}
Full exeption statrack
Full exeption statrack
I think problem with ParameterResolver but idk how fix it.
I use Junit 5.8.0 , junit-jupiter-params 5.11.0-M2
New contributor
k0ct0pka is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.