Skip to content

Commit

Permalink
[Wen Hao] - format code.
Browse files Browse the repository at this point in the history
  • Loading branch information
wenhao committed Feb 8, 2017
1 parent 9b589f9 commit c0bb447
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 103 deletions.
88 changes: 44 additions & 44 deletions src/test/java/com/github/wenhao/jpa/integration/AndTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public class AndTest {
public void should_be_able_to_find_by_using_many_to_one_query() {
// given
final Person jack = new PersonBuilder()
.name("Jack")
.age(18)
.phone("iPhone", "139000000000")
.phone("HuaWei", "13600000000")
.phone("HuaWei", "18000000000")
.phone("Samsung", "13600000000")
.build();
.name("Jack")
.age(18)
.phone("iPhone", "139000000000")
.phone("HuaWei", "13600000000")
.phone("HuaWei", "18000000000")
.phone("Samsung", "13600000000")
.build();

Set<Phone> jackPhones = jack.getPhones();
for (Phone phone : jackPhones) {
Expand All @@ -58,15 +58,15 @@ public void should_be_able_to_find_by_using_many_to_one_query() {

// when
Specification<Phone> specification = Specifications.<Phone>builder()
.eq("brand", "HuaWei")
.and(StringUtils.isNotBlank(jack.getName()), new Specification<Phone>() {
@Override
public Predicate toPredicate(Root<Phone> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Path<Person> person = root.get("person");
return cb.equal(person.get("name"), jack.getName());
}
})
.build();
.eq("brand", "HuaWei")
.and(StringUtils.isNotBlank(jack.getName()), new Specification<Phone>() {
@Override
public Predicate toPredicate(Root<Phone> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Path<Person> person = root.get("person");
return cb.equal(person.get("name"), jack.getName());
}
})
.build();

List<Phone> phones = phoneRepository.findAll(specification);

Expand All @@ -75,47 +75,47 @@ public Predicate toPredicate(Root<Phone> root, CriteriaQuery<?> query, CriteriaB
}

@Test
public void should_be_able_to_find_by_using_many_to_many_query() throws ParseException {
public void should_be_able_to_find_by_using_many_to_many_query() {
// given
Person jack = new PersonBuilder()
.name("Jack")
.age(18)
.address("Sichuan", 3)
.address("Sichuan", 5)
.address("Chengdu", 4)
.address("Zhonghe", 7)
.build();
.name("Jack")
.age(18)
.address("Sichuan", 3)
.address("Sichuan", 5)
.address("Chengdu", 4)
.address("Zhonghe", 7)
.build();

Person eric = new PersonBuilder()
.name("Eric")
.age(20)
.address("GaoXin", 8)
.address("Tianfu", 9)
.address("Chengdu", 4)
.build();
.name("Eric")
.age(20)
.address("GaoXin", 8)
.address("Tianfu", 9)
.address("Chengdu", 4)
.build();

Person alex = new PersonBuilder()
.name("Alex")
.age(30)
.address("HuaYang", 1)
.address("NeiJiang", 2)
.build();
.name("Alex")
.age(30)
.address("HuaYang", 1)
.address("NeiJiang", 2)
.build();

personRepository.save(jack);
personRepository.save(eric);
personRepository.save(alex);

// when
Specification<Person> specification = Specifications.<Person>builder()
.between("age", new Range<Integer>(10, 35))
.and(StringUtils.isNotBlank(jack.getName()), new Specification<Phone>() {
@Override
public Predicate toPredicate(Root<Phone> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Join address = root.join("addresses", JoinType.LEFT);
return cb.equal(address.get("street"), "Chengdu");
}
})
.build();
.between("age", new Range<Integer>(10, 35))
.and(StringUtils.isNotBlank(jack.getName()), new Specification<Phone>() {
@Override
public Predicate toPredicate(Root<Phone> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Join address = root.join("addresses", JoinType.LEFT);
return cb.equal(address.get("street"), "Chengdu");
}
})
.build();


List<Person> phones = personRepository.findAll(specification);
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/com/github/wenhao/jpa/integration/BetweenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ public class BetweenTest {
public void should_be_able_to_find_by_using_between() throws ParseException {
// given
Person jack = new PersonBuilder()
.name("Jack")
.birthday(getDate("1987-11-14"))
.build();
.name("Jack")
.birthday(getDate("1987-11-14"))
.build();
Person eric = new PersonBuilder()
.name("Eric")
.birthday(getDate("1990-10-12"))
.build();
.name("Eric")
.birthday(getDate("1990-10-12"))
.build();
personRepository.save(jack);
personRepository.save(eric);

// when
Specification<Person> specification = Specifications.<Person>builder()
.between(jack.getBirthday() != null, "birthday", new Range<Date>(getDate("1980-01-01"), getDate("1989-12-31")))
.build();
.between(jack.getBirthday() != null, "birthday", new Range<Date>(getDate("1980-01-01"), getDate("1989-12-31")))
.build();

List<Person> persons = personRepository.findAll(specification);

Expand Down
7 changes: 3 additions & 4 deletions src/test/java/com/github/wenhao/jpa/integration/JoinTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.github.wenhao.jpa.integration;

import static org.assertj.core.api.Assertions.assertThat;

import com.github.wenhao.jpa.Specifications;
import com.github.wenhao.jpa.builder.PersonBuilder;
import com.github.wenhao.jpa.model.Person;
Expand All @@ -17,10 +15,11 @@
import org.springframework.data.jpa.domain.Specification;
import org.springframework.test.context.junit4.SpringRunner;

import java.text.ParseException;
import java.util.List;
import java.util.Set;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringRunner.class)
@DataJpaTest
public class JoinTest {
Expand Down Expand Up @@ -61,7 +60,7 @@ public void should_be_able_to_find_by_using_many_to_one_query() {
}

@Test
public void should_be_able_to_find_by_using_many_to_many_query() throws ParseException {
public void should_be_able_to_find_by_using_many_to_many_query() {
// given
Person jack = new PersonBuilder()
.name("Jack")
Expand Down
34 changes: 17 additions & 17 deletions src/test/java/com/github/wenhao/jpa/integration/OrTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@ public class OrTest {
public void should_be_able_to_find_by_using_or_with_multiple_values() {
// given
Person jack = new PersonBuilder()
.name("Jack")
.age(18)
.build();
.name("Jack")
.age(18)
.build();
Person eric = new PersonBuilder()
.name("Eric")
.age(20)
.build();
.name("Eric")
.age(20)
.build();
Person jackson = new PersonBuilder()
.age(30)
.nickName("Jackson")
.build();
.age(30)
.nickName("Jackson")
.build();
personRepository.save(jack);
personRepository.save(eric);
personRepository.save(jackson);

// when
Specification<Person> specification = Specifications.<Person>builder()
.and(OrSpecifications.<Person>builder()
.like("name", "%ac%")
.gt("age", 19)
.eq(jack.getCompany() != null, null)
.ne(jack.getNickName() != null, null)
.between(jack.getBirthday() != null, "birthday", new Range<Date>(new Date(), new Date()))
.build())
.build();
.and(OrSpecifications.<Person>builder()
.like("name", "%ac%")
.gt("age", 19)
.eq(jack.getCompany() != null, null)
.ne(jack.getNickName() != null, null)
.between(jack.getBirthday() != null, "birthday", new Range<Date>(new Date(), new Date()))
.build())
.build();

List<Person> persons = personRepository.findAll(specification);

Expand Down
60 changes: 30 additions & 30 deletions src/test/java/com/github/wenhao/jpa/integration/SortsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ public class SortsTest {
public void should_be_able_to_sort_by_desc() {
// given
Person jack = new PersonBuilder()
.name("Jack")
.age(18)
.build();
.name("Jack")
.age(18)
.build();
Person eric = new PersonBuilder()
.name("Eric")
.age(20)
.build();
.name("Eric")
.age(20)
.build();
Person aaron = new PersonBuilder()
.name("Aaron")
.age(18)
.build();
.name("Aaron")
.age(18)
.build();
personRepository.save(jack);
personRepository.save(eric);
personRepository.save(aaron);

// when
Specification<Person> specification = Specifications.<Person>builder()
.ne("name", null)
.build();
.ne("name", null)
.build();

Sort sort = Sorts.builder()
.desc(jack.getAge() != null, "age")
.desc("name")
.desc(jack.getCompany() != null, "company")
.build();
.desc(jack.getAge() != null, "age")
.desc("name")
.desc(jack.getCompany() != null, "company")
.build();

List<Person> persons = personRepository.findAll(specification, sort);

Expand All @@ -65,31 +65,31 @@ public void should_be_able_to_sort_by_desc() {
public void should_be_able_to_sort_by_asc() {
// given
Person jack = new PersonBuilder()
.name("Jack")
.age(18)
.build();
.name("Jack")
.age(18)
.build();
Person eric = new PersonBuilder()
.name("Eric")
.age(20)
.build();
.name("Eric")
.age(20)
.build();
Person aaron = new PersonBuilder()
.name("Aaron")
.age(18)
.build();
.name("Aaron")
.age(18)
.build();
personRepository.save(jack);
personRepository.save(eric);
personRepository.save(aaron);

// when
Specification<Person> specification = Specifications.<Person>builder()
.ne("name", null)
.build();
.ne("name", null)
.build();

Sort sort = Sorts.builder()
.asc(jack.getAge() != null, "age")
.asc("name")
.asc(jack.getCompany() != null, "company")
.build();
.asc(jack.getAge() != null, "age")
.asc("name")
.asc(jack.getCompany() != null, "company")
.build();

List<Person> persons = personRepository.findAll(specification, sort);

Expand Down

0 comments on commit c0bb447

Please sign in to comment.