我有以下代码(请参见下文),它成功地使用StepVerifier调用ParsePerson :: Parse方法,然后期望"John"和"Mary"的expectNext。
如果ParsePerson :: Parse方法返回一个Person(而不是一个String),我该如何更改StepVerifier以检查每个Person的属性。 与"testPerson"相同的方式
如果ParsePerson :: Parse方法返回一个Person(而不是一个String),我该如何更改StepVerifier以检查每个Person的属性。 与"testPerson"相同的方式
package com.chocksaway;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
/**
* Author milesd on 24/04/2022.
*/
public class TestFluxFilterMono {
@Test
public void testPerson() {
Person john = new Person("John", 22);
StepVerifier.create(Flux.just(john.getName(), john.getAge()))
.expectNext("John", 22)
.expectComplete()
.verify();
}
@Test
public void testCallParse() {
StepVerifier.create(ParsePerson.parse())
.expectNext("John") // how would I check for a Person "John", 22?
.expectNext("Mary") // how would I check for a Person "Mary", 33?
.verifyComplete();
}
}
class ParsePerson {
static Flux<String> parse() {
Flux<Person> peopleList = Flux.just(new Person("John", 22), new Person("Mary", 33));
return peopleList
.filter(each -> each.getAge() > 20)
.map(Person::getName);
}
}
class Person {
private final String name;
private final int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public int getAge() {
return age;
}
public String getName() {
return name;
}
}