Skip to content

Commit 20dfd39

Browse files
committed
Java 16 migration for Map repository examples.
See #606.
1 parent a4c9302 commit 20dfd39

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

ldap/example/pom.xml

+13
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,17 @@
1313
<relativePath>../pom.xml</relativePath>
1414
</parent>
1515

16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>org.apache.maven.plugins</groupId>
20+
<artifactId>maven-surefire-plugin</artifactId>
21+
<configuration>
22+
<argLine>--add-exports=java.naming/com.sun.jndi.ldap=ALL-UNNAMED
23+
</argLine>
24+
</configuration>
25+
</plugin>
26+
</plugins>
27+
</build>
28+
1629
</project>

ldap/example/src/test/java/example/springdata/ldap/PersonRepositoryIntegrationTests.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20-
import java.util.List;
21-
import java.util.Optional;
22-
2320
import javax.naming.InvalidNameException;
2421
import javax.naming.ldap.LdapName;
2522

@@ -47,7 +44,7 @@ public class PersonRepositoryIntegrationTests {
4744
@Test
4845
void findOneByName() throws InvalidNameException {
4946

50-
Optional<Person> person = personRepository.findById(new LdapName("uid=bob,ou=people,dc=springframework,dc=org"));
47+
var person = personRepository.findById(new LdapName("uid=bob,ou=people,dc=springframework,dc=org"));
5148

5249
assertThat(person).hasValueSatisfying(it -> {
5350
assertThat(it.getFullName()).isEqualTo("Bob Hamilton");
@@ -62,7 +59,7 @@ void findOneByName() throws InvalidNameException {
6259
@Test
6360
void findAll() {
6461

65-
Iterable<Person> people = personRepository.findAll();
62+
var people = personRepository.findAll();
6663

6764
assertThat(people).hasSize(3).extracting("uid").contains("bob", "joe", "ben");
6865
}
@@ -73,7 +70,7 @@ void findAll() {
7370
@Test
7471
void findByLastname() {
7572

76-
List<Person> people = personRepository.findByLastnameStartsWith("Ham");
73+
var people = personRepository.findByLastnameStartsWith("Ham");
7774

7875
assertThat(people).hasSize(1).extracting("uid").contains("bob");
7976
}
@@ -86,14 +83,14 @@ void findByLastname() {
8683
@Test
8784
void addUser() throws InvalidNameException {
8885

89-
Person walter = new Person();
86+
var walter = new Person();
9087
walter.setFullName("Walter White");
9188
walter.setUid("heisenberg");
9289
walter.setLastname("White");
9390

9491
personRepository.save(walter);
9592

96-
List<Person> people = personRepository.findByUid("heisenberg");
93+
var people = personRepository.findByUid("heisenberg");
9794

9895
assertThat(people).hasSize(1).extracting("fullName").contains("Walter White");
9996

map/src/test/java/example/springdata/map/PersonRepositoryIntegrationTest.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818
import static org.assertj.core.api.Assertions.*;
1919

20-
import java.util.List;
21-
2220
import org.junit.jupiter.api.Test;
21+
2322
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.boot.autoconfigure.SpringBootApplication;
2524
import org.springframework.boot.test.context.SpringBootTest;
@@ -43,20 +42,19 @@ static class Config {}
4342
@Test
4443
void storesPerson() {
4544

46-
Person person = repository.save(new Person("Dave", "Matthews", 47));
45+
var person = repository.save(new Person("Dave", "Matthews", 47));
4746

4847
assertThat(repository.findById(person.getId())).hasValue(person);
4948
}
5049

5150
@Test
5251
void findsPersonByAge() {
5352

54-
Person dave = repository.save(new Person("Dave", "Matthews", 47));
55-
Person oliver = repository.save(new Person("Oliver August", "Matthews", 7));
53+
var dave = repository.save(new Person("Dave", "Matthews", 47));
54+
var oliver = repository.save(new Person("Oliver August", "Matthews", 7));
5655

57-
List<Person> result = repository.findByAgeGreaterThan(18);
56+
var result = repository.findByAgeGreaterThan(18);
5857

59-
assertThat(result).contains(dave);
60-
assertThat(result).doesNotContain(oliver);
58+
assertThat(result).contains(dave).doesNotContain(oliver);
6159
}
6260
}

0 commit comments

Comments
 (0)