#297 - Fixed failing test due to repository methods now returning Optional.
Also migrated Tests to AssertJ.
This commit is contained in:
committed by
Oliver Gierke
parent
5fcec44ec6
commit
20f6963927
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -15,11 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package example.springdata.jpa.querybyexample;
|
package example.springdata.jpa.querybyexample;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import static org.springframework.data.domain.ExampleMatcher.*;
|
|
||||||
import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.*;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -27,7 +25,7 @@ import org.junit.runner.RunWith;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.data.domain.Example;
|
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;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -36,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
*
|
*
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Oliver Gierke
|
* @author Oliver Gierke
|
||||||
|
* @author Jens Schauder
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@@ -67,7 +66,7 @@ public class UserRepositoryIntegrationTests {
|
|||||||
|
|
||||||
Example<User> example = Example.of(new User(null, "White", null));
|
Example<User> example = Example.of(new User(null, "White", null));
|
||||||
|
|
||||||
assertThat(repository.count(example), is(3L));
|
assertThat(repository.count(example)).isEqualTo(3L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -79,7 +78,7 @@ public class UserRepositoryIntegrationTests {
|
|||||||
Example<User> example = Example.of(flynn, matching().//
|
Example<User> example = Example.of(flynn, matching().//
|
||||||
withIgnorePaths("firstname", "lastname"));
|
withIgnorePaths("firstname", "lastname"));
|
||||||
|
|
||||||
assertThat(repository.findOne(example), is(flynn));
|
assertThat(repository.findOne(example)).contains(flynn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,7 +90,7 @@ public class UserRepositoryIntegrationTests {
|
|||||||
Example<User> example = Example.of(new User("er", null, null), matching().//
|
Example<User> example = Example.of(new User("er", null, null), matching().//
|
||||||
withStringMatcher(StringMatcher.ENDING));
|
withStringMatcher(StringMatcher.ENDING));
|
||||||
|
|
||||||
assertThat(repository.findAll(example), hasItems(skyler, walter));
|
assertThat(repository.findAll(example)).containsExactly(skyler, walter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -106,7 +105,7 @@ public class UserRepositoryIntegrationTests {
|
|||||||
withMatcher("firstname", startsWith()).//
|
withMatcher("firstname", startsWith()).//
|
||||||
withMatcher("lastname", ignoreCase()));
|
withMatcher("lastname", ignoreCase()));
|
||||||
|
|
||||||
assertThat(repository.findAll(example), hasItems(flynn, walter));
|
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,7 +120,7 @@ public class UserRepositoryIntegrationTests {
|
|||||||
withMatcher("firstname", matcher -> matcher.startsWith()).//
|
withMatcher("firstname", matcher -> matcher.startsWith()).//
|
||||||
withMatcher("lastname", matcher -> matcher.ignoreCase()));
|
withMatcher("lastname", matcher -> matcher.ignoreCase()));
|
||||||
|
|
||||||
assertThat(repository.findAll(example), hasItems(flynn, walter));
|
assertThat(repository.findAll(example)).containsExactlyInAnyOrder(flynn, walter);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -133,6 +132,6 @@ public class UserRepositoryIntegrationTests {
|
|||||||
Example<User> example = Example.of(new User(null, "White", 99), matching(). //
|
Example<User> example = Example.of(new User(null, "White", 99), matching(). //
|
||||||
withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));
|
withMatcher("age", matcher -> matcher.transform(value -> Integer.valueOf(50))));
|
||||||
|
|
||||||
assertThat(repository.findAll(example), hasItems(walter));
|
assertThat(repository.findAll(example)).containsExactly(walter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user