From 3d2fbdf3bd9a98a3f58bb01ce174ec842559ebfa Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Fri, 26 Oct 2018 14:50:27 +0200 Subject: [PATCH] Polish mocks with default answer Closes gh-14971 --- .../boot/context/properties/bind/ArrayBinderTests.java | 7 ++----- .../boot/context/properties/bind/BinderTests.java | 7 ++----- .../boot/context/properties/bind/MapBinderTests.java | 7 ++----- .../source/AliasedConfigurationPropertySourceTests.java | 9 ++++----- .../FilteredConfigurationPropertiesSourceTests.java | 7 +++---- 5 files changed, 13 insertions(+), 24 deletions(-) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/ArrayBinderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/ArrayBinderTests.java index 9b5482296ad..41c572fa13f 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/ArrayBinderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/ArrayBinderTests.java @@ -38,7 +38,6 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.withSettings; /** * Tests for {@link ArrayBinder}. @@ -76,8 +75,7 @@ public class ArrayBinderTests { @Test public void bindToCollectionShouldTriggerOnSuccess() { this.sources.add(new MockConfigurationPropertySource("foo[0]", "1", "line1")); - BindHandler handler = mock(BindHandler.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS); this.binder.bind("foo", INTEGER_LIST, handler); InOrder inOrder = inOrder(handler); inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo[0]")), @@ -211,8 +209,7 @@ public class ArrayBinderTests { @Test public void bindToArrayShouldTriggerOnSuccess() { this.sources.add(new MockConfigurationPropertySource("foo[0]", "1", "line1")); - BindHandler handler = mock(BindHandler.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS); Bindable target = INTEGER_ARRAY; this.binder.bind("foo", target, handler); InOrder inOrder = inOrder(handler); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java index f7efc74312c..316dc9bb8f0 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/BinderTests.java @@ -56,7 +56,6 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.withSettings; /** * Tests for {@link Binder}. @@ -170,8 +169,7 @@ public class BinderTests { @Test public void bindToValueShouldTriggerOnSuccess() { this.sources.add(new MockConfigurationPropertySource("foo", "1", "line1")); - BindHandler handler = mock(BindHandler.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS); Bindable target = Bindable.of(Integer.class); this.binder.bind("foo", target, handler); InOrder ordered = inOrder(handler); @@ -210,8 +208,7 @@ public class BinderTests { public void bindToJavaBeanShouldTriggerOnSuccess() { this.sources .add(new MockConfigurationPropertySource("foo.value", "bar", "line1")); - BindHandler handler = mock(BindHandler.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS); Bindable target = Bindable.of(JavaBean.class); this.binder.bind("foo", target, handler); InOrder inOrder = inOrder(handler); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java index 0f38befe519..8a76e698dda 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/bind/MapBinderTests.java @@ -52,7 +52,6 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.withSettings; /** * Tests for {@link MapBinder}. @@ -349,8 +348,7 @@ public class MapBinderTests { @Test public void bindToMapShouldTriggerOnSuccess() { this.sources.add(new MockConfigurationPropertySource("foo.bar", "1", "line1")); - BindHandler handler = mock(BindHandler.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS); Bindable> target = STRING_INTEGER_MAP; this.binder.bind("foo", target, handler); InOrder ordered = inOrder(handler); @@ -364,8 +362,7 @@ public class MapBinderTests { public void bindToMapStringArrayShouldTriggerOnSuccess() { this.sources .add(new MockConfigurationPropertySource("foo.bar", "a,b,c", "line1")); - BindHandler handler = mock(BindHandler.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS); Bindable> target = STRING_ARRAY_MAP; this.binder.bind("foo", target, handler); InOrder ordered = inOrder(handler); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/AliasedConfigurationPropertySourceTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/AliasedConfigurationPropertySourceTests.java index 8d4d15a5270..444842d15ce 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/AliasedConfigurationPropertySourceTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/AliasedConfigurationPropertySourceTests.java @@ -24,7 +24,6 @@ import org.mockito.Answers; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.withSettings; /** * Tests for {@link AliasedConfigurationPropertySource}. @@ -59,7 +58,7 @@ public class AliasedConfigurationPropertySourceTests { public void containsDescendantOfWhenSourceReturnsUnknownShouldReturnUnknown() { ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + Answers.CALLS_REAL_METHODS); given(source.containsDescendantOf(name)) .willReturn(ConfigurationPropertyState.UNKNOWN); ConfigurationPropertySource aliased = source @@ -72,7 +71,7 @@ public class AliasedConfigurationPropertySourceTests { public void containsDescendantOfWhenSourceReturnsPresentShouldReturnPresent() { ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + Answers.CALLS_REAL_METHODS); given(source.containsDescendantOf(name)) .willReturn(ConfigurationPropertyState.PRESENT); given(source.containsDescendantOf(ConfigurationPropertyName.of("bar"))) @@ -87,7 +86,7 @@ public class AliasedConfigurationPropertySourceTests { public void containsDescendantOfWhenAllAreAbsentShouldReturnAbsent() { ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + Answers.CALLS_REAL_METHODS); given(source.containsDescendantOf(name)) .willReturn(ConfigurationPropertyState.ABSENT); given(source.containsDescendantOf(ConfigurationPropertyName.of("bar"))) @@ -102,7 +101,7 @@ public class AliasedConfigurationPropertySourceTests { public void containsDescendantOfWhenAnyIsPresentShouldReturnPresent() { ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + Answers.CALLS_REAL_METHODS); given(source.containsDescendantOf(name)) .willReturn(ConfigurationPropertyState.ABSENT); given(source.containsDescendantOf(ConfigurationPropertyName.of("bar"))) diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/FilteredConfigurationPropertiesSourceTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/FilteredConfigurationPropertiesSourceTests.java index 51e2b57f59d..8f3d2d4d4b7 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/FilteredConfigurationPropertiesSourceTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/source/FilteredConfigurationPropertiesSourceTests.java @@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.withSettings; /** * Test for {@link FilteredIterableConfigurationPropertiesSource}. @@ -67,7 +66,7 @@ public class FilteredConfigurationPropertiesSourceTests { public void containsDescendantOfWhenSourceReturnsEmptyShouldReturnEmpty() { ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + Answers.CALLS_REAL_METHODS); given(source.containsDescendantOf(name)) .willReturn(ConfigurationPropertyState.UNKNOWN); ConfigurationPropertySource filtered = source.filter((n) -> true); @@ -79,7 +78,7 @@ public class FilteredConfigurationPropertiesSourceTests { public void containsDescendantOfWhenSourceReturnsFalseShouldReturnFalse() { ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + Answers.CALLS_REAL_METHODS); given(source.containsDescendantOf(name)) .willReturn(ConfigurationPropertyState.ABSENT); ConfigurationPropertySource filtered = source.filter((n) -> true); @@ -91,7 +90,7 @@ public class FilteredConfigurationPropertiesSourceTests { public void containsDescendantOfWhenSourceReturnsTrueShouldReturnEmpty() { ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, - withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); + Answers.CALLS_REAL_METHODS); given(source.containsDescendantOf(name)) .willReturn(ConfigurationPropertyState.PRESENT); ConfigurationPropertySource filtered = source.filter((n) -> true);