Use modern language features in tests

This commit is contained in:
Sam Brannen
2022-02-03 15:35:32 +01:00
parent 32cd73261a
commit b3f786728e
58 changed files with 117 additions and 151 deletions
@@ -34,21 +34,21 @@ class ParameterizedTypeReferenceTests {
@Test
void stringTypeReference() {
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<String>() {};
ParameterizedTypeReference<String> typeReference = new ParameterizedTypeReference<>() {};
assertThat(typeReference.getType()).isEqualTo(String.class);
}
@Test
void mapTypeReference() throws Exception {
Type mapType = getClass().getMethod("mapMethod").getGenericReturnType();
ParameterizedTypeReference<Map<Object,String>> typeReference = new ParameterizedTypeReference<Map<Object,String>>() {};
ParameterizedTypeReference<Map<Object,String>> typeReference = new ParameterizedTypeReference<>() {};
assertThat(typeReference.getType()).isEqualTo(mapType);
}
@Test
void listTypeReference() throws Exception {
Type listType = getClass().getMethod("listMethod").getGenericReturnType();
ParameterizedTypeReference<List<String>> typeReference = new ParameterizedTypeReference<List<String>>() {};
ParameterizedTypeReference<List<String>> typeReference = new ParameterizedTypeReference<>() {};
assertThat(typeReference.getType()).isEqualTo(listType);
}
@@ -1096,10 +1096,9 @@ class DefaultConversionServiceTests {
@Override
public boolean equals(Object o) {
if (!(o instanceof SSN)) {
if (!(o instanceof SSN ssn)) {
return false;
}
SSN ssn = (SSN) o;
return this.value.equals(ssn.value);
}
@@ -1137,10 +1136,9 @@ class DefaultConversionServiceTests {
@Override
public boolean equals(Object o) {
if (!(o instanceof ISBN)) {
if (!(o instanceof ISBN isbn)) {
return false;
}
ISBN isbn = (ISBN) o;
return this.value.equals(isbn.value);
}
@@ -75,7 +75,7 @@ class CustomEnvironmentTests {
@Override
@SuppressWarnings("serial")
protected Set<String> getReservedDefaultProfiles() {
return new HashSet<String>() {{
return new HashSet<>() {{
add("rd1");
add("rd2");
}};
@@ -37,10 +37,10 @@ class PropertySourceTests {
@Test
@SuppressWarnings("serial")
void equals() {
Map<String, Object> map1 = new HashMap<String, Object>() {{
Map<String, Object> map1 = new HashMap<>() {{
put("a", "b");
}};
Map<String, Object> map2 = new HashMap<String, Object>() {{
Map<String, Object> map2 = new HashMap<>() {{
put("c", "d");
}};
Properties props1 = new Properties() {{
@@ -69,10 +69,10 @@ class PropertySourceTests {
@Test
@SuppressWarnings("serial")
void collectionsOperations() {
Map<String, Object> map1 = new HashMap<String, Object>() {{
Map<String, Object> map1 = new HashMap<>() {{
put("a", "b");
}};
Map<String, Object> map2 = new HashMap<String, Object>() {{
Map<String, Object> map2 = new HashMap<>() {{
put("c", "d");
}};
@@ -41,7 +41,7 @@ class FutureAdapterTests {
@SuppressWarnings("unchecked")
void setUp() {
adaptee = mock(Future.class);
adapter = new FutureAdapter<String, Integer>(adaptee) {
adapter = new FutureAdapter<>(adaptee) {
@Override
protected String adapt(Integer adapteeResult) throws ExecutionException {
return adapteeResult.toString();