#21 - removed intermediate step of creating a Pair.

Avoids an exception, since Pair can not have a null values.
This commit is contained in:
Jens Schauder
2018-01-03 13:14:11 +01:00
parent 72817d62b7
commit 0dc890f7f7
2 changed files with 31 additions and 5 deletions

View File

@@ -52,6 +52,7 @@ import org.springframework.util.Assert;
* @author Oliver Gierke
* @author Philipp Huegelmeyer
* @author Michael Igler
* @author Jens Schauder
*/
public class EnversRevisionRepositoryImpl<T, ID, N extends Number & Comparable<N>> extends SimpleJpaRepository<T, ID>
implements RevisionRepository<T, ID, N> {
@@ -215,8 +216,7 @@ public class EnversRevisionRepositoryImpl<T, ID, N extends Number & Comparable<N
private List<Revision<N, T>> toRevisions(Map<N, T> source, Map<Number, Object> revisionEntities) {
return source.entrySet().stream()//
.map(entry -> Pair.of(revisionEntities.get(entry.getKey()), entry.getValue()))//
.map(pair -> Revision.of((RevisionMetadata<N>) getRevisionMetadata(pair.getFirst()), pair.getSecond()))//
.map(entry -> Revision.of((RevisionMetadata<N>) getRevisionMetadata(revisionEntities.get(entry.getKey())), entry.getValue()))//
.sorted()//
.collect(StreamUtils.toUnmodifiableList());
}

View File

@@ -41,15 +41,18 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Integration tests for repositories.
*
*
* @author Oliver Gierke
* @author Jens Schauder
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Config.class)
public class RepositoryIntegrationTests {
@Autowired LicenseRepository licenseRepository;
@Autowired CountryRepository countryRepository;
@Autowired
LicenseRepository licenseRepository;
@Autowired
CountryRepository countryRepository;
@Before
public void setUp() {
@@ -157,4 +160,27 @@ public class RepositoryIntegrationTests {
assertThat(page.getContent().get(0).getRequiredRevisionNumber())
.isGreaterThan(page.getContent().get(1).getRequiredRevisionNumber());
}
/**
* @see #21
*/
@Test
public void findsDeletedRevisions() {
Country de = new Country();
de.code = "de";
de.name = "Deutschland";
countryRepository.save(de);
countryRepository.delete(de);
Revisions<Integer, Country> revisions = countryRepository.findRevisions(de.id);
assertThat(revisions).hasSize(2);
assertThat(revisions.getLatestRevision().getEntity()) //
.isNotNull() //
.extracting(c -> c.name, c -> c.code) //
.containsExactly(null, null);
}
}