Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,19 @@
* Created by jt on 2/27/21.
*/
public class PersonRepositoryImpl implements PersonRepository {

Person michael = new Person(1, "Michael", "Weston");
Person fiona = new Person(2, "Fiona", "Glenanne");
Person sam = new Person(3, "Sam", "Axe");
Person jesse = new Person(3, "Jesse", "Porter");

@Override
public Mono<Person> getById(Integer id) {
return null;
return Mono.just(michael);
}

@Override
public Flux<Person> findAll() {
return null;
return Flux.just(michael, fiona, sam, jesse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package guru.springframework.reactiveexamples;

import guru.springframework.reactiveexamples.domain.Person;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;

class PersonRepositoryImplTest {

PersonRepositoryImpl personRepository;

@BeforeEach
void setUp() {
personRepository = new PersonRepositoryImpl();
}

@Test
void getByIdBlock() {
Mono<Person> personMono = personRepository.getById(1);

Person person = personMono.block();

System.out.println(person.toString());
}

@Test
void getByIdSubscribe() {
Mono<Person> personMono = personRepository.getById(1);

personMono.subscribe(person -> {
System.out.println(person.toString());
});
}

@Test
void getByIdMapFunction() {
Mono<Person> personMono = personRepository.getById(1);

personMono.map(person -> {
System.out.println(person.toString());

return person.getFirstName();
}).subscribe(firstName -> {
System.out.println("from map: " + firstName);
});
}

@Test
void fluxTestBlockFirst() {
Flux<Person> personFlux = personRepository.findAll();

Person person = personFlux.blockFirst();

System.out.println(person.toString());
}

@Test
void testFluxSubscribe() {
Flux<Person> personFlux = personRepository.findAll();

personFlux.subscribe(person -> {
System.out.println(person.toString());
});
}

@Test
void testFluxToListMono() {
Flux<Person> personFlux = personRepository.findAll();

Mono<List<Person>> personListMono = personFlux.collectList();

personListMono.subscribe(list -> {
list.forEach(person -> {
System.out.println(person.toString());
});
});
}
}