Skip to content

Commit 8fe75df

Browse files
authored
Merge pull request #168 from mmnaseri/release-2.0
Release 2.0 Coverage has decreased due to the tests for the now unused Querydsl-related code having been ignored.
2 parents 40f941f + cf7eae4 commit 8fe75df

File tree

498 files changed

+3185
-2132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

498 files changed

+3185
-2132
lines changed

.travis.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
language: java
22
jdk:
3-
- oraclejdk7
4-
- oraclejdk8
3+
- openjdk8
4+
- openjdk9
5+
- openjdk10
6+
- openjdk11
57
script:
68
- cd spring-data-mock
79
- mvn test -B
810
after_success:
911
- cd spring-data-mock-build
1012
- mvn -P coverage clean cobertura:cobertura coveralls:report
11-
- '[[ $TRAVIS_BRANCH == "master" && ( "x${TRAVIS_PULL_REQUEST}" == "xfalse" || "x${TRAVIS_PULL_REQUEST}" == "x" ) && ( "x$(echo $JAVA_HOME | grep -o 8)" == "x8" ) ]] && sudo apt-get install gnupg2'
12-
- '[[ $TRAVIS_BRANCH == "master" && ( "x${TRAVIS_PULL_REQUEST}" == "xfalse" || "x${TRAVIS_PULL_REQUEST}" == "x" ) && ( "x$(echo $JAVA_HOME | grep -o 8)" == "x8" ) ]] && bash ../deployment/deploy.sh eb1a6f34f056 ../deployment/key.asc.enc ../deployment/settings.xml'
13-
# SUDO should be set to `false` except when deploying to OSSRH to trigger container infrastructure
14-
sudo: true
13+
- '[[ $TRAVIS_BRANCH == "master" && ( "x${TRAVIS_PULL_REQUEST}" == "xfalse" || "x${TRAVIS_PULL_REQUEST}" == "x" ) && ( "x$(echo $JAVA_HOME | grep -o 11)" == "x11" ) ]] && sudo apt-get install gnupg2'
14+
- '[[ $TRAVIS_BRANCH == "master" && ( "x${TRAVIS_PULL_REQUEST}" == "xfalse" || "x${TRAVIS_PULL_REQUEST}" == "x" ) && ( "x$(echo $JAVA_HOME | grep -o 11)" == "x11" ) ]] && bash ../deployment/deploy.sh eb1a6f34f056 ../deployment/key.asc.enc ../deployment/settings.xml'
15+
os: linux
16+
dist: xenial
1517
env:
1618
global:
1719
- secure: DPkao3yJ4hhEsUOfs2VQJ8WCV3VdR3ToFiGB1l461PUstjaytTeXYK3bW2PmZqYJs6Hxxwyl8UHFvgBvWLb/yQV/dqyyJAV8XRb9UC37e4ddLoi8HE7NSGQIiXq0tySiMaOTyd2NtRTepfNAMEMDP746Nrox1giPEq1FPv+K98o=

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
[![Donae](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://paypal.me/mmnaseri)
55
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
66
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.mmnaseri.utils/spring-data-mock/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.mmnaseri.utils/spring-data-mock)
7-
[![Dependency Status](https://www.versioneye.com/user/projects/5722a8f5ba37ce0031fc17f0/badge.svg?style=flat)](https://www.versioneye.com/user/projects/5722a8f5ba37ce0031fc17f0)
87
[![Build Status](https://travis-ci.org/mmnaseri/spring-data-mock.svg?branch=master)](https://travis-ci.org/mmnaseri/spring-data-mock)
98
[![Codacy Badge](https://api.codacy.com/project/badge/grade/ad9f174fa0654a2b8c925b86973f272d)](https://www.codacy.com/app/mmnaseri/spring-data-mock)
109
[![Coverage Status](https://coveralls.io/repos/github/mmnaseri/spring-data-mock/badge.svg?branch=master)](https://coveralls.io/github/mmnaseri/spring-data-mock?branch=master)
@@ -100,8 +99,20 @@ There you can get more information on how to download the framework, as well as
10099
incorporate it in your project to have hassle-free data store mocking capabilities added to
101100
your shiny applications.
102101

102+
## Breaking Changes since v2.0
103+
104+
`v2.0` introduces compatibility with Spring Boot 2.0, but also creates some incompatibilities with prior versions.
105+
106+
- As well it should, it is now adopting all the new method signatures for the new Spring Data, meaning that those
107+
are now automatic breaking changes.
108+
- We have now dropped support for Querydsl repositories until further notice, due to compiler issues with the EJC
109+
dependency used by Querydsl.
110+
- The library now runs on Java 8+, meaning we do not support JDK 7 anymore.
111+
103112
## History
104113

114+
- 2.0 Upgrade to Spring Boot 2.0 (many thanks to binakot@). This is a major release and breaks some stuff.
115+
105116
- 1.1 Add QueryDSL and findByExample support
106117

107118
see [site changelog](https://mmnaseri.github.io/spring-data-mock/site/#/changelog)

spring-data-mock-build/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
<groupId>com.mmnaseri.utils</groupId>
2828
<artifactId>spring-data-mock-build</artifactId>
29-
<version>1.1.0</version>
29+
<version>2.0.0</version>
3030
<packaging>pom</packaging>
3131

3232
<name>Spring Data Mock: Build Aggregator</name>
@@ -65,8 +65,8 @@
6565

6666
<properties>
6767
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
68-
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
69-
<target-jdk.version>1.7</target-jdk.version>
68+
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
69+
<target-jdk.version>1.8</target-jdk.version>
7070
</properties>
7171

7272
<build>

spring-data-mock-sample-jpa/pom.xml

+10-6
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
</developers>
3333

3434
<properties>
35-
<spring-data-commons.version>1.12.1.RELEASE</spring-data-commons.version>
36-
<spring-data-jpa.version>1.10.1.RELEASE</spring-data-jpa.version>
35+
<spring-data-commons.version>2.2.6.RELEASE</spring-data-commons.version>
36+
<spring-data-jpa.version>2.2.6.RELEASE</spring-data-jpa.version>
3737
<persistence-api.version>1.0.2</persistence-api.version>
38-
<spring-data-mock.version>1.1.4</spring-data-mock.version>
39-
<testng.version>6.9.6</testng.version>
38+
<spring-data-mock.version>2.0.0</spring-data-mock.version>
39+
<testng.version>7.1.0</testng.version>
4040
<hamcrest.version>1.3</hamcrest.version>
4141
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
42-
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
43-
<target-jdk.version>1.7</target-jdk.version>
42+
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
43+
<target-jdk.version>1.8</target-jdk.version>
4444
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
4545
</properties>
4646

@@ -77,6 +77,10 @@
7777
<artifactId>spring-data-mock</artifactId>
7878
<version>${spring-data-mock.version}</version>
7979
<scope>test</scope>
80+
81+
<!-- Build with local build of library. Uncomment one row above and comment two rows below for production environment. -->
82+
<!-- <scope>system</scope>-->
83+
<!-- <systemPath>${project.basedir}/../spring-data-mock/target/spring-data-mock-2.0.0.jar</systemPath>-->
8084
</dependency>
8185
</dependencies>
8286

spring-data-mock-sample-jpa/src/main/java/com/mmnaseri/utils/samples/spring/data/jpa/service/impl/DefaultCustomerService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public long register(String firstName, String lastName, Date birthday) {
3232
}
3333

3434
public Customer findCustomer(long id) {
35-
return repository.findOne(id);
35+
return repository.findById(id).orElse(null);
3636
}
3737

3838
public List<Customer> findCustomersByBirthday(Date from, Date to) {

spring-data-mock-sample-jpa/src/main/java/com/mmnaseri/utils/samples/spring/data/jpa/service/impl/DefaultGroupService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public Group createGroup(String name) {
3434
@Override
3535
public void deleteGroup(Group group) {
3636
final List<Membership> memberships = membershipRepository.findByGroup(group);
37-
membershipRepository.delete(memberships);
37+
membershipRepository.deleteAll(memberships);
3838
groupRepository.delete(group);
3939
}
4040

spring-data-mock-sample-jpa/src/main/java/com/mmnaseri/utils/samples/spring/data/jpa/service/impl/DefaultPlaneService.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ public Long create(String model, String serial) {
2727

2828
@Override
2929
public String lookup(Long id) {
30-
final Plane plane = repository.findOne(id);
31-
if (plane == null) {
32-
return null;
33-
}
34-
return plane.getModel();
30+
return repository.findById(id).map(Plane::getModel).orElse(null);
3531
}
3632

3733
@Override

spring-data-mock-sample-jpa/src/test/java/com/mmnaseri/utils/samples/spring/data/jpa/service/impl/DefaultCustomerServiceTest.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
import static com.mmnaseri.utils.spring.data.dsl.factory.RepositoryFactoryBuilder.builder;
1515
import static org.hamcrest.MatcherAssert.assertThat;
16-
import static org.hamcrest.Matchers.*;
16+
import static org.hamcrest.Matchers.containsInAnyOrder;
17+
import static org.hamcrest.Matchers.hasSize;
18+
import static org.hamcrest.Matchers.is;
19+
import static org.hamcrest.Matchers.notNullValue;
1720

1821
/**
1922
* @author Mohammad Milad Naseri ([email protected])
@@ -44,7 +47,7 @@ public void testCustomerRegistration() throws Exception {
4447
//after registration, we should have exactly one record
4548
assertThat(repository.count(), is(1L));
4649
//and we should be able to load the cutomer by it's ID
47-
final Customer customer = repository.findOne(id);
50+
final Customer customer = repository.findById(id).orElse(null);
4851
//and that customer should be the one we registered
4952
assertThat(customer, is(notNullValue()));
5053
assertThat(customer.getId(), is(id));

spring-data-mock-sample-jpa/src/test/java/com/mmnaseri/utils/samples/spring/data/jpa/service/impl/DefaultGroupServiceTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import java.util.List;
1717

1818
import static org.hamcrest.MatcherAssert.assertThat;
19-
import static org.hamcrest.Matchers.*;
19+
import static org.hamcrest.Matchers.hasSize;
20+
import static org.hamcrest.Matchers.is;
21+
import static org.hamcrest.Matchers.notNullValue;
2022

2123
/**
2224
* @author Milad Naseri ([email protected])
@@ -47,7 +49,7 @@ public void testCreatingAGroup() throws Exception {
4749
assertThat(group, is(notNullValue()));
4850
assertThat(group.getName(), is(name));
4951
assertThat(groupRepository.count(), is(1L));
50-
final Group found = groupRepository.findOne(group.getId());
52+
final Group found = groupRepository.findById(group.getId()).orElse(null);
5153
assertThat(found, is(notNullValue()));
5254
assertThat(found.getName(), is(name));
5355
}

spring-data-mock-sample-jpa/src/test/java/com/mmnaseri/utils/samples/spring/data/jpa/service/impl/DefaultPlaneServiceTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import org.testng.annotations.BeforeMethod;
1111
import org.testng.annotations.Test;
1212

13-
import java.io.Serializable;
14-
1513
import static org.hamcrest.MatcherAssert.assertThat;
1614
import static org.hamcrest.Matchers.is;
1715
import static org.hamcrest.Matchers.notNullValue;
@@ -41,7 +39,7 @@ public void tearDown() throws Exception {
4139
//the tests, too.
4240
//This is the same as using a shared database for doing all the tests. So, at the end of the tests we need
4341
//to clear the database after us like using a regular data store
44-
final DataStore<Serializable, Plane> dataStore = configuration.getDataStoreRegistry().getDataStore(Plane.class);
42+
final DataStore<Object, Plane> dataStore = configuration.getDataStoreRegistry().getDataStore(Plane.class);
4543
dataStore.truncate();
4644
}
4745

@@ -52,7 +50,7 @@ public void testCreate() throws Exception {
5250
final String serial = "123456";
5351
final Long id = service.create(model, serial);
5452
assertThat(id, is(notNullValue()));
55-
final Plane loaded = repository.findOne(id);
53+
final Plane loaded = repository.findById(id).orElse(null);
5654
assertThat(loaded, is(notNullValue()));
5755
assertThat(loaded.getModel(), is(model));
5856
assertThat(loaded.getSerial(), is(serial));

spring-data-mock-sample-jpa/src/test/java/com/mmnaseri/utils/samples/spring/data/jpa/service/impl/DefaultUserServiceTest.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
import org.testng.annotations.Test;
1414

1515
import static org.hamcrest.MatcherAssert.assertThat;
16-
import static org.hamcrest.Matchers.*;
16+
import static org.hamcrest.Matchers.hasSize;
17+
import static org.hamcrest.Matchers.is;
18+
import static org.hamcrest.Matchers.not;
19+
import static org.hamcrest.Matchers.notNullValue;
20+
import static org.hamcrest.Matchers.nullValue;
1721

1822
/**
1923
* @author Milad Naseri ([email protected])
@@ -49,7 +53,7 @@ public void testCreatingAUser() throws Exception {
4953
assertThat(user.getEmail(), is(email));
5054
assertThat(user.getPasswordHash(), is(not(password)));
5155
assertThat(repository.count(), is(1L));
52-
final User found = repository.findOne(user.getId());
56+
final User found = repository.findById(user.getId()).orElse(null);
5357
assertThat(found, is(notNullValue()));
5458
assertThat(found.getUsername(), is(username));
5559
assertThat(found.getEmail(), is(email));

spring-data-mock/pom.xml

+13-21
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
<groupId>com.mmnaseri.utils</groupId>
2929
<artifactId>spring-data-mock</artifactId>
30-
<version>1.1.4</version>
30+
<version>2.0.0</version>
3131

3232
<name>Spring Data Mock</name>
3333
<description>A framework for mocking Spring Data repositories</description>
@@ -65,28 +65,27 @@
6565
<properties>
6666
<!-- build integrity -->
6767
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
68-
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
69-
<target-jdk.version>1.7</target-jdk.version>
68+
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
69+
<target-jdk.version>1.8</target-jdk.version>
7070
<!-- requirements -->
7171
<commons-logging.version>1.2</commons-logging.version>
72-
<joda-time.version>2.9.4</joda-time.version>
7372
<!-- test -->
74-
<testng.version>6.9.12</testng.version>
73+
<testng.version>7.1.0</testng.version>
7574
<hamcrest.version>1.3</hamcrest.version>
7675
<!-- deployment -->
7776
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
78-
<maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version>
79-
<maven-source-plugin.version>3.0.1</maven-source-plugin.version>
77+
<maven-javadoc-plugin.version>3.2.0</maven-javadoc-plugin.version>
78+
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
8079
<maven-deploy-plugin.version>2.8.2</maven-deploy-plugin.version>
81-
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
80+
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
8281
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
83-
<coveralls-maven-plugin.version>4.2.0</coveralls-maven-plugin.version>
82+
<coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
8483
<!-- feature support -->
85-
<spring-data-commons.version>1.12.2.RELEASE</spring-data-commons.version>
86-
<spring-data-gemfire.version>1.8.2.RELEASE</spring-data-gemfire.version>
87-
<spring-data-jpa.version>1.10.2.RELEASE</spring-data-jpa.version>
88-
<querydsl.version>4.1.2</querydsl.version>
89-
<cglib.version>3.2.4</cglib.version>
84+
<spring-data-commons.version>2.2.6.RELEASE</spring-data-commons.version>
85+
<spring-data-gemfire.version>2.2.6.RELEASE</spring-data-gemfire.version>
86+
<spring-data-jpa.version>2.2.6.RELEASE</spring-data-jpa.version>
87+
<querydsl.version>4.3.1</querydsl.version>
88+
<cglib.version>3.3.0</cglib.version>
9089
<persistence-api.version>1.0.2</persistence-api.version>
9190
</properties>
9291

@@ -139,13 +138,6 @@
139138
<version>${spring-data-commons.version}</version>
140139
<scope>provided</scope>
141140
</dependency>
142-
<dependency>
143-
<!-- needed for adding support for Spring Data audit functionality -->
144-
<groupId>joda-time</groupId>
145-
<artifactId>joda-time</artifactId>
146-
<version>${joda-time.version}</version>
147-
<scope>provided</scope>
148-
</dependency>
149141
<dependency>
150142
<!-- Spring Data support for JPA-->
151143
<groupId>org.springframework.data</groupId>

spring-data-mock/src/main/java/com/mmnaseri/utils/spring/data/domain/DataStoreAware.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@
22

33
import com.mmnaseri.utils.spring.data.store.DataStore;
44

5-
import java.io.Serializable;
6-
75
/**
8-
* This interface is used to inject {@link DataStore the data store} into a concrete class aiming to provide method mapping
9-
* for a repository.
6+
* This interface is used to inject {@link DataStore the data store} into a concrete class aiming to provide method
7+
* mapping for a repository.
108
*
11-
* @author Milad Naseri ([email protected])
9+
* @author Milad Naseri ([email protected])
1210
* @since 1.0 (9/29/15)
1311
*/
14-
public interface DataStoreAware<E, K extends Serializable> {
12+
public interface DataStoreAware<E, K> {
1513

1614
<J extends K, F extends E> void setDataStore(DataStore<J, F> dataStore);
1715

Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
package com.mmnaseri.utils.spring.data.domain;
22

3-
import java.io.Serializable;
4-
53
/**
6-
* An id property resolver will be capable of looking at an entity class and find the name of the property that
7-
* is the ID property of that class based on the expected type of the identifier.
4+
* An id property resolver will be capable of looking at an entity class and find the name of the property that is the
5+
* ID property of that class based on the expected type of the identifier.
86
*
9-
* @author Milad Naseri ([email protected])
7+
* @author Milad Naseri ([email protected])
108
* @since 1.0 (9/23/15)
119
*/
1210
public interface IdPropertyResolver {
1311

1412
/**
15-
* Resolves the name of the ID <em>property</em>. If the property is accessible through a getter, it will
16-
* still return the name of the underlying property accessible by the getter by converting the name of the getter
17-
* to the bare property name.
18-
* @param entityType the type of the entity on which the key is defined
19-
* @param idType the expected type (or supertype) for the ID property
13+
* Resolves the name of the ID <em>property</em>. If the property is accessible through a getter, it will still
14+
* return the name of the underlying property accessible by the getter by converting the name of the getter to the
15+
* bare property name.
16+
*
17+
* @param entityType the type of the entity on which the key is defined
18+
* @param idType the expected type (or supertype) for the ID property
2019
* @return the name of the property that represents the key to the entity
2120
*/
22-
String resolve(Class<?> entityType, Class<? extends Serializable> idType);
21+
String resolve(Class<?> entityType, Class<?> idType);
2322

2423
}

spring-data-mock/src/main/java/com/mmnaseri/utils/spring/data/domain/Invocation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* This interface encapsulates a single invocation, regardless of the object on which the method was invoked.
77
*
8-
* @author Milad Naseri ([email protected])
8+
* @author Milad Naseri ([email protected])
99
* @since 1.0 (9/17/15)
1010
*/
1111
public interface Invocation {

spring-data-mock/src/main/java/com/mmnaseri/utils/spring/data/domain/InvocationMatcher.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
* through a method invocation. This is used to determine whether or not an entity in the data store matches the
66
* parameters passed to a query method according to the criteria defined by that query method.
77
*
8-
* @author Milad Naseri ([email protected])
8+
* @author Milad Naseri ([email protected])
99
* @since 1.0 (9/17/15)
1010
*/
1111
public interface InvocationMatcher {
1212

1313
/**
1414
* Determines whether or not the entity matches the query
15-
* @param entity the entity
16-
* @param invocation the query method invocation
15+
*
16+
* @param entity the entity
17+
* @param invocation the query method invocation
1718
* @return {@literal true} if it was a match
1819
*/
1920
boolean matches(Object entity, Invocation invocation);

0 commit comments

Comments
 (0)