There is a simply class:
class Person {
private int age;
private String name;
public String getName(){return this.name;}
public int getAge(){return this.age;}
public void setName(String name){this.name = name;}
public void setAge(int age){this.age = age;}
}
and I have a methods getPersonNameWithPrefix()
and getPeopleNames()
in SearchPeople
interface with implement in SearchPeopleImpl
:
class SearchPeopleImpl implements SearchPeople {
public String getPersonNameWithPrefix(Person person){
return "prefix" + person.getName();
}
public List<String> getPeopleNames(List<Person> peopleList){
return peopleList.stream().map(Person::getName).collect(Collectors.toList());
}
}
I want to use parameters in my test and it looks like:
def 'test Person name'(){
given:
def searchPeople = new SearchPeopleImpl ()
def person = Mock(Person){
getName() >> a
}
when:
def name = searchPeople.getPersonNameWithPrefix(person)
then:
name == b
where:
a | b
"AA" | "prefixAA"
"BB" | "prefixBB"
"CC" | "prefixCC"
}
it works well but I have a problem with test my second method. How is it possible to put list of elements into table
(in where
section), use it as method parameter and then expect another list of objects? I mean that I want to declare a few list of Person
objects and then check that method returns correct list of Strings
Aucun commentaire:
Enregistrer un commentaire