From 80b70e6bd2f4c5940c4748c452fe9939fc12b603 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Wed, 31 May 2017 15:21:08 +0200 Subject: [PATCH] #297 - Fixed failing test due to repository methods now returning Optional. Also migrated Tests to AssertJ. Fixed compilation failure due to changed API of CollectionOptions --- .../UserRepositoryIntegrationTests.java | 25 +++++++++---------- ...activePersonRepositoryIntegrationTest.java | 2 +- ...xJava1PersonRepositoryIntegrationTest.java | 5 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java index 8166f6a8..e5c2146b 100644 --- a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java +++ b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,11 +15,9 @@ */ package example.springdata.mongodb.querybyexample; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import static org.springframework.data.domain.ExampleMatcher.*; +import static org.assertj.core.api.Assertions.*; import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*; -import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.startsWith; +import static org.springframework.data.domain.ExampleMatcher.*; import org.junit.Before; import org.junit.Test; @@ -27,7 +25,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Example; -import org.springframework.data.domain.ExampleMatcher.StringMatcher; +import org.springframework.data.domain.ExampleMatcher.*; import org.springframework.test.context.junit4.SpringRunner; /** @@ -35,6 +33,7 @@ import org.springframework.test.context.junit4.SpringRunner; * * @author Mark Paluch * @author Oliver Gierke + * @author Jens Schauder */ @SuppressWarnings("unused") @RunWith(SpringRunner.class) @@ -65,7 +64,7 @@ public class UserRepositoryIntegrationTests { Example example = Example.of(new Person(null, "White", null)); - assertThat(repository.count(example), is(3L)); + assertThat(repository.count(example)).isEqualTo(3L); } /** @@ -77,7 +76,7 @@ public class UserRepositoryIntegrationTests { Example example = Example.of(flynn, matching(). // withIgnorePaths("firstname", "lastname")); - assertThat(repository.findOne(example), is(flynn)); + assertThat(repository.findOne(example)).contains(flynn); } /** @@ -89,7 +88,7 @@ public class UserRepositoryIntegrationTests { Example example = Example.of(new Person("er", null, null), matching().// withStringMatcher(StringMatcher.ENDING)); - assertThat(repository.findAll(example), hasItems(skyler, walter)); + assertThat(repository.findAll(example)).containsExactlyInAnyOrder(skyler, walter); } /** @@ -101,7 +100,7 @@ public class UserRepositoryIntegrationTests { Example example = Example.of(new Person("(Skyl|Walt)er", null, null), matching().// withMatcher("firstname", matcher -> matcher.regex())); - assertThat(repository.findAll(example), hasItems(skyler, walter)); + assertThat(repository.findAll(example)).contains(skyler, walter); } /** @@ -116,7 +115,7 @@ public class UserRepositoryIntegrationTests { withMatcher("firstname", startsWith()).// withMatcher("lastname", ignoreCase())); - assertThat(repository.findAll(example), hasItems(flynn, walter)); + assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter); } /** @@ -131,7 +130,7 @@ public class UserRepositoryIntegrationTests { withMatcher("firstname", matcher -> matcher.startsWith()).// withMatcher("lastname", matcher -> matcher.ignoreCase())); - assertThat(repository.findAll(example), hasItems(flynn, walter)); + assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter); } /** @@ -143,6 +142,6 @@ public class UserRepositoryIntegrationTests { Example example = Example.of(new Person(null, "White", 99), matching(). // withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50)))); - assertThat(repository.findAll(example), hasItems(walter)); + assertThat(repository.findAll(example)).containsExactlyInAnyOrder(walter); } } diff --git a/mongodb/reactive/src/test/java/example/springdata/mongodb/people/ReactivePersonRepositoryIntegrationTest.java b/mongodb/reactive/src/test/java/example/springdata/mongodb/people/ReactivePersonRepositoryIntegrationTest.java index 3483ee5e..2f14eca7 100644 --- a/mongodb/reactive/src/test/java/example/springdata/mongodb/people/ReactivePersonRepositoryIntegrationTest.java +++ b/mongodb/reactive/src/test/java/example/springdata/mongodb/people/ReactivePersonRepositoryIntegrationTest.java @@ -50,7 +50,7 @@ public class ReactivePersonRepositoryIntegrationTest { operations.collectionExists(Person.class) // .flatMap(exists -> exists ? operations.dropCollection(Person.class) : Mono.just(exists)) // - .flatMap(o -> operations.createCollection(Person.class, new CollectionOptions(1024 * 1024, 100, true))) // + .flatMap(o -> operations.createCollection(Person.class, CollectionOptions.empty().size(1024 * 1024).maxDocuments( 100).capped())) // .then() // .block(); diff --git a/mongodb/reactive/src/test/java/example/springdata/mongodb/people/RxJava1PersonRepositoryIntegrationTest.java b/mongodb/reactive/src/test/java/example/springdata/mongodb/people/RxJava1PersonRepositoryIntegrationTest.java index 997b0c38..6467e29c 100644 --- a/mongodb/reactive/src/test/java/example/springdata/mongodb/people/RxJava1PersonRepositoryIntegrationTest.java +++ b/mongodb/reactive/src/test/java/example/springdata/mongodb/people/RxJava1PersonRepositoryIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -41,6 +41,7 @@ import org.springframework.test.context.junit4.SpringRunner; * reactive flavors. * * @author Mark Paluch + * @author Jens Schauder */ @RunWith(SpringRunner.class) @SpringBootTest @@ -54,7 +55,7 @@ public class RxJava1PersonRepositoryIntegrationTest { operations.collectionExists(Person.class) // .flatMap(exists -> exists ? operations.dropCollection(Person.class) : Mono.just(exists)) // - .flatMap(o -> operations.createCollection(Person.class, new CollectionOptions(1024 * 1024, 100, true))) // + .flatMap(o -> operations.createCollection(Person.class, CollectionOptions.empty().size(1024 * 1024).maxDocuments(100).capped())) // .then() // .block();