From dfa8a7c358ad2b1a23d814c9b0f96d75004ddbe1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 16 Feb 2017 15:57:52 +0100 Subject: [PATCH] Polishing --- .../support/PropertyComparatorTests.java | 36 +++++++++---------- .../comparator/CompoundComparatorTests.java | 6 ++-- .../comparator/InvertibleComparatorTests.java | 26 ++++++-------- .../jdbc/core/JdbcTemplateTests.java | 22 ++++++++---- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java b/spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java index 09d74c73f4b..bc168716708 100644 --- a/spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,7 @@ import org.springframework.util.comparator.CompoundComparator; import static org.junit.Assert.*; /** - * Unit tests for {@link PropertyComparator} - * - * @see org.springframework.util.comparator.ComparatorTests + * Unit tests for {@link PropertyComparator}. * * @author Keith Donald * @author Chris Beams @@ -40,7 +38,7 @@ public class PropertyComparatorTests { Dog dog2 = new Dog(); dog2.setNickName("biscy"); - PropertyComparator c = new PropertyComparator("nickName", false, true); + PropertyComparator c = new PropertyComparator<>("nickName", false, true); assertTrue(c.compare(dog, dog2) > 0); assertTrue(c.compare(dog, dog) == 0); assertTrue(c.compare(dog2, dog) < 0); @@ -50,15 +48,14 @@ public class PropertyComparatorTests { public void testPropertyComparatorNulls() { Dog dog = new Dog(); Dog dog2 = new Dog(); - PropertyComparator c = new PropertyComparator("nickName", false, true); + PropertyComparator c = new PropertyComparator<>("nickName", false, true); assertTrue(c.compare(dog, dog2) == 0); } - @SuppressWarnings("unchecked") @Test public void testCompoundComparator() { - CompoundComparator c = new CompoundComparator(); - c.addComparator(new PropertyComparator("lastName", false, true)); + CompoundComparator c = new CompoundComparator<>(); + c.addComparator(new PropertyComparator<>("lastName", false, true)); Dog dog1 = new Dog(); dog1.setFirstName("macy"); @@ -70,19 +67,19 @@ public class PropertyComparatorTests { assertTrue(c.compare(dog1, dog2) == 0); - c.addComparator(new PropertyComparator("firstName", false, true)); + c.addComparator(new PropertyComparator<>("firstName", false, true)); assertTrue(c.compare(dog1, dog2) > 0); dog2.setLastName("konikk dog"); assertTrue(c.compare(dog2, dog1) > 0); } - @SuppressWarnings("unchecked") @Test public void testCompoundComparatorInvert() { - CompoundComparator c = new CompoundComparator(); - c.addComparator(new PropertyComparator("lastName", false, true)); - c.addComparator(new PropertyComparator("firstName", false, true)); + CompoundComparator c = new CompoundComparator<>(); + c.addComparator(new PropertyComparator<>("lastName", false, true)); + c.addComparator(new PropertyComparator<>("firstName", false, true)); + Dog dog1 = new Dog(); dog1.setFirstName("macy"); dog1.setLastName("grayspots"); @@ -97,7 +94,6 @@ public class PropertyComparatorTests { } - @SuppressWarnings("unused") private static class Dog implements Comparable { private String nickName; @@ -106,11 +102,6 @@ public class PropertyComparatorTests { private String lastName; - @Override - public int compareTo(Object o) { - return nickName.compareTo(((Dog)o).nickName); - } - public String getNickName() { return nickName; } @@ -134,6 +125,11 @@ public class PropertyComparatorTests { public void setLastName(String lastName) { this.lastName = lastName; } + + @Override + public int compareTo(Object o) { + return this.nickName.compareTo(((Dog) o).nickName); + } } } diff --git a/spring-core/src/test/java/org/springframework/util/comparator/CompoundComparatorTests.java b/spring-core/src/test/java/org/springframework/util/comparator/CompoundComparatorTests.java index 10d5ca33c78..8032808c355 100644 --- a/spring-core/src/test/java/org/springframework/util/comparator/CompoundComparatorTests.java +++ b/spring-core/src/test/java/org/springframework/util/comparator/CompoundComparatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.junit.Test; import org.junit.rules.ExpectedException; /** - * Test for {@link ComparableComparator}. + * Test for {@link CompoundComparator}. * * @author Keith Donald * @author Chris Beams @@ -36,7 +36,7 @@ public class CompoundComparatorTests { @Test public void shouldNeedAtLeastOneComparator() { - Comparator c = new CompoundComparator(); + Comparator c = new CompoundComparator<>(); thrown.expect(IllegalStateException.class); c.compare("foo", "bar"); } diff --git a/spring-core/src/test/java/org/springframework/util/comparator/InvertibleComparatorTests.java b/spring-core/src/test/java/org/springframework/util/comparator/InvertibleComparatorTests.java index c8afa7a690a..d78f69c7407 100644 --- a/spring-core/src/test/java/org/springframework/util/comparator/InvertibleComparatorTests.java +++ b/spring-core/src/test/java/org/springframework/util/comparator/InvertibleComparatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,33 +30,31 @@ import static org.junit.Assert.*; * @author Chris Beams * @author Phillip Webb */ - public class InvertibleComparatorTests { - private Comparator comparator = new ComparableComparator(); + private final Comparator comparator = new ComparableComparator<>(); - @Test(expected=IllegalArgumentException.class) + + @Test(expected = IllegalArgumentException.class) public void shouldNeedComparator() throws Exception { - new InvertibleComparator(null); + new InvertibleComparator<>(null); } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void shouldNeedComparatorWithAscending() throws Exception { - new InvertibleComparator(null, true); + new InvertibleComparator<>(null, true); } @Test public void shouldDefaultToAscending() throws Exception { - InvertibleComparator invertibleComparator = - new InvertibleComparator(comparator); + InvertibleComparator invertibleComparator = new InvertibleComparator<>(comparator); assertThat(invertibleComparator.isAscending(), is(true)); assertThat(invertibleComparator.compare(1, 2), is(-1)); } @Test public void shouldInvert() throws Exception { - InvertibleComparator invertibleComparator = - new InvertibleComparator(comparator); + InvertibleComparator invertibleComparator = new InvertibleComparator<>(comparator); assertThat(invertibleComparator.isAscending(), is(true)); assertThat(invertibleComparator.compare(1, 2), is(-1)); invertibleComparator.invertOrder(); @@ -66,15 +64,13 @@ public class InvertibleComparatorTests { @Test public void shouldCompareAscending() throws Exception { - InvertibleComparator invertibleComparator = - new InvertibleComparator(comparator, true); + InvertibleComparator invertibleComparator = new InvertibleComparator<>(comparator, true); assertThat(invertibleComparator.compare(1, 2), is(-1)); } @Test public void shouldCompareDescending() throws Exception { - InvertibleComparator invertibleComparator = - new InvertibleComparator(comparator, false); + InvertibleComparator invertibleComparator = new InvertibleComparator<>(comparator, false); assertThat(invertibleComparator.compare(1, 2), is(1)); } diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java index 5cc3b8ebb16..b98b77c312a 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java @@ -67,16 +67,23 @@ import static org.springframework.tests.Matchers.*; */ public class JdbcTemplateTests { + private Connection connection; + + private DataSource dataSource; + + private PreparedStatement preparedStatement; + + private Statement statement; + + private ResultSet resultSet; + + private JdbcTemplate template; + + private CallableStatement callableStatement; + @Rule public ExpectedException thrown = ExpectedException.none(); - private Connection connection; - private DataSource dataSource; - private PreparedStatement preparedStatement; - private Statement statement; - private ResultSet resultSet; - private JdbcTemplate template; - private CallableStatement callableStatement; @Before public void setup() throws Exception { @@ -98,6 +105,7 @@ public class JdbcTemplateTests { given(this.callableStatement.getResultSet()).willReturn(this.resultSet); } + @Test public void testBeanProperties() throws Exception { assertTrue("datasource ok", this.template.getDataSource() == this.dataSource);