I'm writing a simple reactive app, using spring5 and mongo reactive repositories. I wanted to test repos, followed tutorials, but still have problem:
java.lang.AssertionError: expectation "assertNext" failed (expected: onNext(); actual: onComplete())
Here is my entity:
@Document(collection = "products")
@TypeAlias("product")
@Getter
@Builder
@AllArgsConstructor
@EqualsAndHashCode
public class Product {
@Id
private ObjectId _id;
private String productName;
private Integer quantityPerUnit;
private BigDecimal unitPrice;
private Integer unitsInStock;
private Boolean discount;
private String categoryName;
private Supplier supplier;
}
repo, nothing special:
public interface ProductRepository extends ReactiveMongoRepository<Product, String> {
}
and finally test:
@DataMongoTest
@RunWith(SpringRunner.class)
public class ProductRepositoryTest {
@Autowired
private ProductRepository productRepository;
@Test
public void shouldReturnOneProductWithExpected() {
String expectedId = "54759ab3c090d83494e2d804";
productRepository.save(first).block();
Mono<Product> product = productRepository.findById(Mono.just("54759ab3c090d83494e2d804"));
StepVerifier
.create(product)
.assertNext(prod -> {
assertNotNull(prod);
assertThat(prod.get_id(), is(equalTo(expectedId)));
})
.expectComplete()
.verify();
}
}
Does anyone have idea why it's not working?