#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
This commit is contained in:
Jens Schauder
2017-05-31 15:21:08 +02:00
committed by Oliver Gierke
parent 20f6963927
commit 80b70e6bd2
3 changed files with 16 additions and 16 deletions

View File

@@ -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<Person> 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<Person> 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<Person> 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<Person> 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<Person> 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);
}
}

View File

@@ -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();

View File

@@ -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();