📍Use lombok, reformat, and optimize the code (#1560)

* Use lombok, reformat, and optimize the code

* Fix merge conflicts and some sonar issues

Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
va1m
2021-03-13 13:19:21 +01:00
committed by GitHub
parent 0e26a6adb5
commit 5cf2fe009b
681 changed files with 2472 additions and 4966 deletions

View File

@ -33,11 +33,6 @@
</parent>
<artifactId>repository</artifactId>
<dependencies>
<dependency>
<groupId>com.github.sbrannen</groupId>
<artifactId>spring-test-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>

View File

@ -24,8 +24,7 @@
package com.iluwatar.repository;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
@ -43,10 +42,9 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
* also performed. Underneath we have configured in-memory H2 database for which schema is created
* and dropped on each run.
*/
@Slf4j
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point.
*

View File

@ -26,10 +26,9 @@ package com.iluwatar.repository;
import java.util.List;
import java.util.Properties;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.dbcp.BasicDataSource;
import org.hibernate.jpa.HibernatePersistenceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@ -42,10 +41,9 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
*/
@EnableJpaRepositories
@SpringBootConfiguration
@Slf4j
public class AppConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(AppConfig.class);
/**
* Creation of H2 db.
*

View File

@ -26,11 +26,21 @@ package com.iluwatar.repository;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
/**
* Person entity.
*/
@ToString
@EqualsAndHashCode
@Setter
@Getter
@Entity
@NoArgsConstructor
public class Person {
@Id
@ -38,12 +48,8 @@ public class Person {
private Long id;
private String name;
private String surname;
private int age;
public Person() {
}
/**
* Constructor.
*/
@ -53,87 +59,4 @@ public class Person {
this.age = age;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public String toString() {
return "Person [id=" + id + ", name=" + name + ", surname=" + surname + ", age=" + age + "]";
}
@Override
public int hashCode() {
final var prime = 31;
var result = 1;
result = prime * result + age;
result = prime * result + (id == null ? 0 : id.hashCode());
result = prime * result + (name == null ? 0 : name.hashCode());
result = prime * result + (surname == null ? 0 : surname.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
var other = (Person) obj;
if (age != other.age) {
return false;
}
if (id == null) {
if (other.id != null) {
return false;
}
} else if (!id.equals(other.id)) {
return false;
}
if (name == null) {
if (other.name != null) {
return false;
}
} else if (!name.equals(other.name)) {
return false;
}
if (surname == null) {
return other.surname == null;
}
return surname.equals(other.surname);
}
}

View File

@ -43,7 +43,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = {AppConfig.class})
public class AnnotationBasedRepositoryTest {
class AnnotationBasedRepositoryTest {
@Resource
private PersonRepository repository;
@ -64,13 +64,13 @@ public class AnnotationBasedRepositoryTest {
}
@Test
public void testFindAll() {
void testFindAll() {
var actuals = Lists.newArrayList(repository.findAll());
assertTrue(actuals.containsAll(persons) && persons.containsAll(actuals));
}
@Test
public void testSave() {
void testSave() {
var terry = repository.findByName("Terry");
terry.setSurname("Lee");
terry.setAge(47);
@ -82,7 +82,7 @@ public class AnnotationBasedRepositoryTest {
}
@Test
public void testDelete() {
void testDelete() {
var terry = repository.findByName("Terry");
repository.delete(terry);
@ -91,12 +91,12 @@ public class AnnotationBasedRepositoryTest {
}
@Test
public void testCount() {
void testCount() {
assertEquals(4, repository.count());
}
@Test
public void testFindAllByAgeBetweenSpec() {
void testFindAllByAgeBetweenSpec() {
var persons = repository.findAll(new PersonSpecifications.AgeBetweenSpec(20, 40));
assertEquals(3, persons.size());
@ -104,7 +104,7 @@ public class AnnotationBasedRepositoryTest {
}
@Test
public void testFindOneByNameEqualSpec() {
void testFindOneByNameEqualSpec() {
var actual = repository.findOne(new PersonSpecifications.NameEqualSpec("Terry"));
assertTrue(actual.isPresent());
assertEquals(terry, actual.get());

View File

@ -26,7 +26,6 @@ package com.iluwatar.repository;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import org.junit.jupiter.api.Test;
@ -41,7 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = {AppConfig.class})
public class AppConfigTest {
class AppConfigTest {
@Autowired
DataSource dataSource;
@ -50,7 +49,7 @@ public class AppConfigTest {
* Test for bean instance
*/
@Test
public void testDataSource() {
void testDataSource() {
assertNotNull(dataSource);
}
@ -59,7 +58,7 @@ public class AppConfigTest {
*/
@Test
@Transactional
public void testQuery() throws SQLException {
void testQuery() throws SQLException {
var resultSet = dataSource.getConnection().createStatement().executeQuery("SELECT 1");
var expected = "1";
String result = null;

View File

@ -43,7 +43,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(properties = {"locations=classpath:applicationContext.xml"})
public class RepositoryTest {
class RepositoryTest {
@Resource
private PersonRepository repository;
@ -64,13 +64,13 @@ public class RepositoryTest {
}
@Test
public void testFindAll() {
void testFindAll() {
var actuals = Lists.newArrayList(repository.findAll());
assertTrue(actuals.containsAll(persons) && persons.containsAll(actuals));
}
@Test
public void testSave() {
void testSave() {
var terry = repository.findByName("Terry");
terry.setSurname("Lee");
terry.setAge(47);
@ -82,7 +82,7 @@ public class RepositoryTest {
}
@Test
public void testDelete() {
void testDelete() {
var terry = repository.findByName("Terry");
repository.delete(terry);
@ -91,12 +91,12 @@ public class RepositoryTest {
}
@Test
public void testCount() {
void testCount() {
assertEquals(4, repository.count());
}
@Test
public void testFindAllByAgeBetweenSpec() {
void testFindAllByAgeBetweenSpec() {
var persons = repository.findAll(new PersonSpecifications.AgeBetweenSpec(20, 40));
assertEquals(3, persons.size());
@ -104,7 +104,7 @@ public class RepositoryTest {
}
@Test
public void testFindOneByNameEqualSpec() {
void testFindOneByNameEqualSpec() {
var actual = repository.findOne(new PersonSpecifications.NameEqualSpec("Terry"));
assertTrue(actual.isPresent());
assertEquals(terry, actual.get());