Skip to content

Commit dfa8a7c

Browse files
committed
Polishing
1 parent 427fd9b commit dfa8a7c

File tree

4 files changed

+41
-41
lines changed

4 files changed

+41
-41
lines changed

spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,9 +23,7 @@
2323
import static org.junit.Assert.*;
2424

2525
/**
26-
* Unit tests for {@link PropertyComparator}
27-
*
28-
* @see org.springframework.util.comparator.ComparatorTests
26+
* Unit tests for {@link PropertyComparator}.
2927
*
3028
* @author Keith Donald
3129
* @author Chris Beams
@@ -40,7 +38,7 @@ public void testPropertyComparator() {
4038
Dog dog2 = new Dog();
4139
dog2.setNickName("biscy");
4240

43-
PropertyComparator c = new PropertyComparator("nickName", false, true);
41+
PropertyComparator<Dog> c = new PropertyComparator<>("nickName", false, true);
4442
assertTrue(c.compare(dog, dog2) > 0);
4543
assertTrue(c.compare(dog, dog) == 0);
4644
assertTrue(c.compare(dog2, dog) < 0);
@@ -50,15 +48,14 @@ public void testPropertyComparator() {
5048
public void testPropertyComparatorNulls() {
5149
Dog dog = new Dog();
5250
Dog dog2 = new Dog();
53-
PropertyComparator c = new PropertyComparator("nickName", false, true);
51+
PropertyComparator<Dog> c = new PropertyComparator<>("nickName", false, true);
5452
assertTrue(c.compare(dog, dog2) == 0);
5553
}
5654

57-
@SuppressWarnings("unchecked")
5855
@Test
5956
public void testCompoundComparator() {
60-
CompoundComparator<Dog> c = new CompoundComparator<Dog>();
61-
c.addComparator(new PropertyComparator("lastName", false, true));
57+
CompoundComparator<Dog> c = new CompoundComparator<>();
58+
c.addComparator(new PropertyComparator<>("lastName", false, true));
6259

6360
Dog dog1 = new Dog();
6461
dog1.setFirstName("macy");
@@ -70,19 +67,19 @@ public void testCompoundComparator() {
7067

7168
assertTrue(c.compare(dog1, dog2) == 0);
7269

73-
c.addComparator(new PropertyComparator("firstName", false, true));
70+
c.addComparator(new PropertyComparator<>("firstName", false, true));
7471
assertTrue(c.compare(dog1, dog2) > 0);
7572

7673
dog2.setLastName("konikk dog");
7774
assertTrue(c.compare(dog2, dog1) > 0);
7875
}
7976

80-
@SuppressWarnings("unchecked")
8177
@Test
8278
public void testCompoundComparatorInvert() {
83-
CompoundComparator<Dog> c = new CompoundComparator<Dog>();
84-
c.addComparator(new PropertyComparator("lastName", false, true));
85-
c.addComparator(new PropertyComparator("firstName", false, true));
79+
CompoundComparator<Dog> c = new CompoundComparator<>();
80+
c.addComparator(new PropertyComparator<>("lastName", false, true));
81+
c.addComparator(new PropertyComparator<>("firstName", false, true));
82+
8683
Dog dog1 = new Dog();
8784
dog1.setFirstName("macy");
8885
dog1.setLastName("grayspots");
@@ -97,7 +94,6 @@ public void testCompoundComparatorInvert() {
9794
}
9895

9996

100-
@SuppressWarnings("unused")
10197
private static class Dog implements Comparable<Object> {
10298

10399
private String nickName;
@@ -106,11 +102,6 @@ private static class Dog implements Comparable<Object> {
106102

107103
private String lastName;
108104

109-
@Override
110-
public int compareTo(Object o) {
111-
return nickName.compareTo(((Dog)o).nickName);
112-
}
113-
114105
public String getNickName() {
115106
return nickName;
116107
}
@@ -134,6 +125,11 @@ public String getLastName() {
134125
public void setLastName(String lastName) {
135126
this.lastName = lastName;
136127
}
128+
129+
@Override
130+
public int compareTo(Object o) {
131+
return this.nickName.compareTo(((Dog) o).nickName);
132+
}
137133
}
138134

139135
}

spring-core/src/test/java/org/springframework/util/comparator/CompoundComparatorTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
2323
import org.junit.rules.ExpectedException;
2424

2525
/**
26-
* Test for {@link ComparableComparator}.
26+
* Test for {@link CompoundComparator}.
2727
*
2828
* @author Keith Donald
2929
* @author Chris Beams
@@ -36,7 +36,7 @@ public class CompoundComparatorTests {
3636

3737
@Test
3838
public void shouldNeedAtLeastOneComparator() {
39-
Comparator<String> c = new CompoundComparator<String>();
39+
Comparator<String> c = new CompoundComparator<>();
4040
thrown.expect(IllegalStateException.class);
4141
c.compare("foo", "bar");
4242
}

spring-core/src/test/java/org/springframework/util/comparator/InvertibleComparatorTests.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,33 +30,31 @@
3030
* @author Chris Beams
3131
* @author Phillip Webb
3232
*/
33-
3433
public class InvertibleComparatorTests {
3534

36-
private Comparator<Integer> comparator = new ComparableComparator<Integer>();
35+
private final Comparator<Integer> comparator = new ComparableComparator<>();
36+
3737

38-
@Test(expected=IllegalArgumentException.class)
38+
@Test(expected = IllegalArgumentException.class)
3939
public void shouldNeedComparator() throws Exception {
40-
new InvertibleComparator<Object>(null);
40+
new InvertibleComparator<>(null);
4141
}
4242

43-
@Test(expected=IllegalArgumentException.class)
43+
@Test(expected = IllegalArgumentException.class)
4444
public void shouldNeedComparatorWithAscending() throws Exception {
45-
new InvertibleComparator<Object>(null, true);
45+
new InvertibleComparator<>(null, true);
4646
}
4747

4848
@Test
4949
public void shouldDefaultToAscending() throws Exception {
50-
InvertibleComparator<Integer> invertibleComparator =
51-
new InvertibleComparator<Integer>(comparator);
50+
InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator);
5251
assertThat(invertibleComparator.isAscending(), is(true));
5352
assertThat(invertibleComparator.compare(1, 2), is(-1));
5453
}
5554

5655
@Test
5756
public void shouldInvert() throws Exception {
58-
InvertibleComparator<Integer> invertibleComparator =
59-
new InvertibleComparator<Integer>(comparator);
57+
InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator);
6058
assertThat(invertibleComparator.isAscending(), is(true));
6159
assertThat(invertibleComparator.compare(1, 2), is(-1));
6260
invertibleComparator.invertOrder();
@@ -66,15 +64,13 @@ public void shouldInvert() throws Exception {
6664

6765
@Test
6866
public void shouldCompareAscending() throws Exception {
69-
InvertibleComparator<Integer> invertibleComparator =
70-
new InvertibleComparator<Integer>(comparator, true);
67+
InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator, true);
7168
assertThat(invertibleComparator.compare(1, 2), is(-1));
7269
}
7370

7471
@Test
7572
public void shouldCompareDescending() throws Exception {
76-
InvertibleComparator<Integer> invertibleComparator =
77-
new InvertibleComparator<Integer>(comparator, false);
73+
InvertibleComparator<Integer> invertibleComparator = new InvertibleComparator<>(comparator, false);
7874
assertThat(invertibleComparator.compare(1, 2), is(1));
7975
}
8076

spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,24 @@
6767
*/
6868
public class JdbcTemplateTests {
6969

70-
@Rule
71-
public ExpectedException thrown = ExpectedException.none();
72-
7370
private Connection connection;
71+
7472
private DataSource dataSource;
73+
7574
private PreparedStatement preparedStatement;
75+
7676
private Statement statement;
77+
7778
private ResultSet resultSet;
79+
7880
private JdbcTemplate template;
81+
7982
private CallableStatement callableStatement;
8083

84+
@Rule
85+
public ExpectedException thrown = ExpectedException.none();
86+
87+
8188
@Before
8289
public void setup() throws Exception {
8390
this.connection = mock(Connection.class);
@@ -98,6 +105,7 @@ public void setup() throws Exception {
98105
given(this.callableStatement.getResultSet()).willReturn(this.resultSet);
99106
}
100107

108+
101109
@Test
102110
public void testBeanProperties() throws Exception {
103111
assertTrue("datasource ok", this.template.getDataSource() == this.dataSource);

0 commit comments

Comments
 (0)