Polishing.

Reformat code. Simplify annotation setup.

See #603
Original pull request: #604.
This commit is contained in:
Mark Paluch
2021-02-25 09:30:13 +01:00
parent fef817eb22
commit 53dc64ecb4
5 changed files with 23 additions and 25 deletions

View File

@@ -1,15 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spring-data-jpa-examples</artifactId>
<groupId>org.springframework.data.examples</groupId>
<version>2.0.0.BUILD-gh-603-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.data.examples</groupId>
<artifactId>spring-data-jpa-examples</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-data-jpa-envers</artifactId> <artifactId>spring-data-jpa-envers</artifactId>
<name>Spring Data Envers</name>
<dependencies> <dependencies>
<dependency> <dependency>
@@ -17,4 +18,5 @@
<artifactId>spring-data-envers</artifactId> <artifactId>spring-data-envers</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@@ -22,8 +22,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
/** /**
* Configuration for the Envers Demo. * Configuration for the Envers Demo.
* <p> * <p>
* Note that a special {@literal repositoryFactoryBeanClass} is configured for Spring * Note that a special {@literal repositoryFactoryBeanClass} is configured for Spring Data Envers support.
* Data Envers support.
* *
* @author Jens Schauder * @author Jens Schauder
*/ */

View File

@@ -15,13 +15,13 @@
*/ */
package example.springdata.jpa.envers; package example.springdata.jpa.envers;
import org.hibernate.envers.Audited;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Version; import javax.persistence.Version;
import org.hibernate.envers.Audited;
/** /**
* An entity with a single non-technical attribute * An entity with a single non-technical attribute
* *

View File

@@ -23,5 +23,4 @@ import org.springframework.data.repository.history.RevisionRepository;
* *
* @author Jens Schauder * @author Jens Schauder
*/ */
public interface PersonRepository extends CrudRepository<Person, Long>, RevisionRepository<Person, Long, Long> { public interface PersonRepository extends CrudRepository<Person, Long>, RevisionRepository<Person, Long, Long> {}
}

View File

@@ -17,24 +17,22 @@ package example.springdata.jpa.envers;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import java.util.Iterator;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
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.history.Revision; import org.springframework.data.history.Revision;
import org.springframework.data.history.RevisionMetadata.RevisionType; import org.springframework.data.history.RevisionMetadata.RevisionType;
import org.springframework.data.history.Revisions; import org.springframework.data.history.Revisions;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.support.TransactionTemplate; import org.springframework.transaction.support.TransactionTemplate;
import java.util.Iterator;
/** /**
* Demonstrating the usage of Spring Data Envers * Demonstrating the usage of Spring Data Envers
* *
* @author Jens Schauder * @author Jens Schauder
*/ */
@ExtendWith(SpringExtension.class)
@SpringBootTest @SpringBootTest
public class EnversIntegrationTests { public class EnversIntegrationTests {
@@ -48,7 +46,6 @@ public class EnversIntegrationTests {
Revisions<Long, Person> revisions = repository.findRevisions(updated.id); Revisions<Long, Person> revisions = repository.findRevisions(updated.id);
Iterator<Revision<Long, Person>> revisionIterator = revisions.iterator(); Iterator<Revision<Long, Person>> revisionIterator = revisions.iterator();
checkNextRevision(revisionIterator, "John", RevisionType.INSERT); checkNextRevision(revisionIterator, "John", RevisionType.INSERT);
@@ -58,7 +55,8 @@ public class EnversIntegrationTests {
} }
private void checkNextRevision(Iterator<Revision<Long, Person>> revisionIterator, String name, RevisionType revisionType) { private void checkNextRevision(Iterator<Revision<Long, Person>> revisionIterator, String name,
RevisionType revisionType) {
assertThat(revisionIterator.hasNext()).isTrue(); assertThat(revisionIterator.hasNext()).isTrue();
Revision<Long, Person> revision = revisionIterator.next(); Revision<Long, Person> revision = revisionIterator.next();
@@ -71,7 +69,7 @@ public class EnversIntegrationTests {
Person john = new Person(); Person john = new Person();
john.setName("John"); john.setName("John");
//create // create
Person saved = tx.execute(__ -> repository.save(john)); Person saved = tx.execute(__ -> repository.save(john));
assertThat(saved).isNotNull(); assertThat(saved).isNotNull();
@@ -82,7 +80,7 @@ public class EnversIntegrationTests {
assertThat(updated).isNotNull(); assertThat(updated).isNotNull();
// delete // delete
tx.executeWithoutResult(__->repository.delete(updated)); tx.executeWithoutResult(__ -> repository.delete(updated));
return updated; return updated;
} }
} }