Skip to content

Commit

Permalink
Merge pull request #170 from mmnaseri/release-v2.1.0
Browse files Browse the repository at this point in the history
Release v2.1.0
  • Loading branch information
mmnaseri committed Apr 26, 2020
2 parents 8fe75df + e193590 commit 183dcaf
Show file tree
Hide file tree
Showing 285 changed files with 1,785 additions and 1,166 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom: ['https://paypal.me/mmnaseri']
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ target

# Mac OS X junk
.DS_Store

# Generated encryption keys
deployment/key.enc
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ script:
after_success:
- cd spring-data-mock-build
- mvn -P coverage clean cobertura:cobertura coveralls:report
- '[[ $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'
- '[[ $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'
- '[[ $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'
- '[[ $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'
os: linux
dist: xenial
env:
Expand Down
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM ubuntu:xenial
RUN apt update
RUN apt install openjdk-8-jdk -y
RUN apt install maven -y
VOLUME /src
WORKDIR /src
CMD "bash"
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ FAQ
Also, the people behind Spring rock. I felt like I was selling tickets to the concert of rockstars by releasing
this.

3. What is the main design decision behind this framework?
3. What is the main design principle behind this framework?

> Make you do as little as possible.

4. When should I use this?

> You should only use this to write you *unit* tests. For anything else, you would want the whole application to
> You should only use this to write your *unit* tests. For anything else, you would want the whole application to
come alive and work. Using mocks for that is a bad idea.

5. This is going to be used at the level of code testing. Is it really well written?
Expand All @@ -154,7 +154,7 @@ Some Numbers and Facts

* This project has *1000+* individual unit tests.

* This project has **100%** [code coverage](https://coveralls.io/github/mmnaseri/spring-data-mock)
* This project has effective **100%** (deprecated code is not tested) [code coverage](https://coveralls.io/github/mmnaseri/spring-data-mock)

* This project has **95%** branch coverage rate.

Expand All @@ -171,8 +171,8 @@ Some Numbers and Facts
Contribution
------------

Since this project is aimed at the testing phase of your code, it is paramount that it is written with the best of
qualities and that it maintains the highest standard.
Since this project aims to help you in the testing phase of your code, it is paramount that it is
written with the best of qualities and that it maintains the highest standard.

Contributors are more than welcome. In fact, I flag most of the issues I receive as `help wanted` and
there are really generous people out there who do take care of some issues.
Expand All @@ -181,6 +181,17 @@ If you see a piece of code that you don't like for whatever reason -- so long as
by pioneers and standards -- feel free to dig in and change the code to your heart's content and create a
pull request.

### Building the Code

To make the code builds universal and canonical, I have a Docker configuration attached to this project
which installs OpenJDK 8 on Ubuntu Xenial. This is the build environment I will be using to test and release
the code.

```bash
docker build -t spring-data-mock:jdk8 .
docker run -it --rm -v $(pwd):/src spring-data-mock:jdk8
```

Donation
--------

Expand Down
25 changes: 14 additions & 11 deletions deployment/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#
# Deploy to sonatype by installing gnupg2, decrypting and installing a gpg secret key, and invoking mvn deploy.

function die() {
die() {
echo "$@" >&2
exit -1
exit 1
}

#######################################
Expand All @@ -16,7 +16,7 @@ function die() {
# Returns:
# None
#######################################
function checkTravisSecure() {
checkTravisSecure() {
if [[ $TRAVIS_SECURE_ENV_VARS != "true" ]]; then
echo "no secure env vars available, skipping deployment"
exit
Expand All @@ -32,7 +32,7 @@ function checkTravisSecure() {
# Returns:
# None
#######################################
function usage() {
usage() {
echo "${0} gpg-decryption-hash gpg-key-file"
}

Expand All @@ -46,7 +46,7 @@ function usage() {
# Returns:
# The value of the encrypted variable
#######################################
function encryption_value() {
encryption_value() {
local -r HASH="$1"
local -r NAME="$2"
local -r ENCRYPTED_VARIABLE="encrypted_${HASH}_${NAME}"
Expand All @@ -65,7 +65,7 @@ function encryption_value() {
# Returns:
# None
#######################################
function install_gpg_key() {
install_gpg_key() {
local -r KEY="$1"
local -r IV="$2"
local -r ENC_KEY_FILE="$3"
Expand All @@ -84,7 +84,7 @@ function install_gpg_key() {
# Returns:
# None
#######################################
function install_gpg() {
install_gpg() {
sudo apt-get update -qq
sudo apt-get install -y gnupg2
}
Expand All @@ -98,8 +98,11 @@ function install_gpg() {
# Returns:
# None
#######################################
function mvn_deploy() {
mvn_deploy() {
local -r SETTINGS_FILE="$1"
# Allowing loopback entry on GnuPG 2.1+
echo "allow-loopback-pinentry" > ~/.gnupg/gpg-agent.conf
gpgconf --reload gpg-agent
mvn -P release clean deploy -Drelease -s "$SETTINGS_FILE"
}

Expand All @@ -114,18 +117,18 @@ function mvn_deploy() {
# Returns:
# None
#######################################
function main() {
main() {
checkTravisSecure

if (($# < 3)); then
die $(usage)
die "$(usage)"
fi
local -r HASH="$1"
local -r ENC_GPG_KEY_FILE="$2"
local -r MVN_SETTINGS_FILE="$3"

install_gpg
install_gpg_key $(encryption_value "$HASH" key) $(encryption_value "$HASH" iv) "$ENC_GPG_KEY_FILE" "${ENC_GPG_KEY_FILE/.asc}"
install_gpg_key "$(encryption_value "$HASH" key)" "$(encryption_value "$HASH" iv)" "$ENC_GPG_KEY_FILE" "${ENC_GPG_KEY_FILE/.asc}"
mvn_deploy "$MVN_SETTINGS_FILE"
}

Expand Down
1 change: 1 addition & 0 deletions spring-data-mock-build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<modules>
<module>../spring-data-mock/</module>
<module>../spring-data-mock-sample-jpa</module>
<module>../spring-data-mock-sample-mongo</module>
</modules>

<scm>
Expand Down
6 changes: 1 addition & 5 deletions spring-data-mock-sample-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@
</developers>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-data-commons.version>2.2.6.RELEASE</spring-data-commons.version>
<spring-data-jpa.version>2.2.6.RELEASE</spring-data-jpa.version>
<persistence-api.version>1.0.2</persistence-api.version>
<spring-data-mock.version>2.0.0</spring-data-mock.version>
<testng.version>7.1.0</testng.version>
<hamcrest.version>1.3</hamcrest.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
<target-jdk.version>1.8</target-jdk.version>
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
Expand Down Expand Up @@ -77,10 +77,6 @@
<artifactId>spring-data-mock</artifactId>
<version>${spring-data-mock.version}</version>
<scope>test</scope>

<!-- Build with local build of library. Uncomment one row above and comment two rows below for production environment. -->
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/../spring-data-mock/target/spring-data-mock-2.0.0.jar</systemPath>-->
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @since 1.0 (6/12/16, 1:50 PM)
*/
@Entity
@SuppressWarnings("unused")
public class Customer {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* @author Milad Naseri (milad.naseri@cdk.com)
* @since 1.0 (6/29/16, 4:03 PM)
*/
@SuppressWarnings("unused")
@Entity
public class Group {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @since 1.0 (6/29/16, 4:04 PM)
*/
@Entity
@SuppressWarnings("unused")
public class Membership {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @since 1.0 (6/14/16, 11:34 PM)
*/
@Entity
@SuppressWarnings("unused")
public class Plane extends SerialAwareEntity {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @since 1.0 (6/29/16, 4:03 PM)
*/
@Entity
@SuppressWarnings("unused")
public class User {

@Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.data.domain.Example;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Collection;
import java.util.Date;
import java.util.List;

Expand All @@ -15,6 +16,10 @@ public interface CustomerRepository extends JpaRepository<Customer, Long> {

List<Customer> findByBirthdayBetween(Date from, Date to);

@SuppressWarnings("SpringDataMethodInconsistencyInspection") // This is covered in a custom impl.
List<Customer> findByExample(Example<Customer> probe);

List<Customer> findByFirstNameIn(Collection<String> firstNames);

List<Customer> findByFirstNameIgnoreCaseContaining(String substring);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import com.mmnaseri.utils.samples.spring.data.jpa.model.Customer;

import java.util.Collection;
import java.util.Date;
import java.util.List;

/**
* @author Mohammad Milad Naseri (m.m.naseri@gmail.com)
* @since 1.0 (6/12/16, 1:51 PM)
*/
@SuppressWarnings("unused")
public interface CustomerService {

long register(String firstName, String lastName, Date birthday);
Expand All @@ -19,4 +21,8 @@ public interface CustomerService {

List<Customer> findCustomersByName(String firstName, String lastName);

List<Customer> findCustomersByFirstNames(Collection<String> firstNames);

List<Customer> findByFirstNamePart(String part);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @author Milad Naseri (milad.naseri@cdk.com)
* @since 1.0 (6/14/16, 11:39 PM)
*/
@SuppressWarnings("unused")
public interface PlaneService {

Long create(String model, String serial);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @author Milad Naseri (milad.naseri@cdk.com)
* @since 1.0 (6/29/16, 4:06 PM)
*/
@SuppressWarnings("unused")
public interface UserService {

User createUser(String username, String email, String password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;

import java.util.Collection;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -50,4 +51,13 @@ public List<Customer> findCustomersByName(String firstName, String lastName) {
return repository.findByExample(example);
}

public List<Customer> findCustomersByFirstNames(Collection<String> firstNames) {
return repository.findByFirstNameIn(firstNames);
}

@Override
public List<Customer> findByFirstNamePart(final String part) {
return repository.findByFirstNameIgnoreCaseContaining(part);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* @author Mohammad Milad Naseri (m.m.naseri@gmail.com)
* @since 1.0 (6/12/16, 5:30 PM)
*/
@SuppressWarnings("unused")
public class CustomerRepositoryExampleSupport implements RepositoryAware<CustomerRepository> {

private CustomerRepository repository;
Expand Down
Loading

0 comments on commit 183dcaf

Please sign in to comment.