Commit 3d2fbdf3 authored by dreis2211's avatar dreis2211 Committed by Phillip Webb

Polish mocks with default answer

Closes gh-14971
parent c393f626
...@@ -38,7 +38,6 @@ import static org.mockito.ArgumentMatchers.eq; ...@@ -38,7 +38,6 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA; import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.withSettings;
/** /**
* Tests for {@link ArrayBinder}. * Tests for {@link ArrayBinder}.
...@@ -76,8 +75,7 @@ public class ArrayBinderTests { ...@@ -76,8 +75,7 @@ public class ArrayBinderTests {
@Test @Test
public void bindToCollectionShouldTriggerOnSuccess() { public void bindToCollectionShouldTriggerOnSuccess() {
this.sources.add(new MockConfigurationPropertySource("foo[0]", "1", "line1")); this.sources.add(new MockConfigurationPropertySource("foo[0]", "1", "line1"));
BindHandler handler = mock(BindHandler.class, BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
this.binder.bind("foo", INTEGER_LIST, handler); this.binder.bind("foo", INTEGER_LIST, handler);
InOrder inOrder = inOrder(handler); InOrder inOrder = inOrder(handler);
inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo[0]")), inOrder.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo[0]")),
...@@ -211,8 +209,7 @@ public class ArrayBinderTests { ...@@ -211,8 +209,7 @@ public class ArrayBinderTests {
@Test @Test
public void bindToArrayShouldTriggerOnSuccess() { public void bindToArrayShouldTriggerOnSuccess() {
this.sources.add(new MockConfigurationPropertySource("foo[0]", "1", "line1")); this.sources.add(new MockConfigurationPropertySource("foo[0]", "1", "line1"));
BindHandler handler = mock(BindHandler.class, BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
Bindable<Integer[]> target = INTEGER_ARRAY; Bindable<Integer[]> target = INTEGER_ARRAY;
this.binder.bind("foo", target, handler); this.binder.bind("foo", target, handler);
InOrder inOrder = inOrder(handler); InOrder inOrder = inOrder(handler);
......
...@@ -56,7 +56,6 @@ import static org.mockito.ArgumentMatchers.eq; ...@@ -56,7 +56,6 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA; import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.withSettings;
/** /**
* Tests for {@link Binder}. * Tests for {@link Binder}.
...@@ -170,8 +169,7 @@ public class BinderTests { ...@@ -170,8 +169,7 @@ public class BinderTests {
@Test @Test
public void bindToValueShouldTriggerOnSuccess() { public void bindToValueShouldTriggerOnSuccess() {
this.sources.add(new MockConfigurationPropertySource("foo", "1", "line1")); this.sources.add(new MockConfigurationPropertySource("foo", "1", "line1"));
BindHandler handler = mock(BindHandler.class, BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
Bindable<Integer> target = Bindable.of(Integer.class); Bindable<Integer> target = Bindable.of(Integer.class);
this.binder.bind("foo", target, handler); this.binder.bind("foo", target, handler);
InOrder ordered = inOrder(handler); InOrder ordered = inOrder(handler);
...@@ -210,8 +208,7 @@ public class BinderTests { ...@@ -210,8 +208,7 @@ public class BinderTests {
public void bindToJavaBeanShouldTriggerOnSuccess() { public void bindToJavaBeanShouldTriggerOnSuccess() {
this.sources this.sources
.add(new MockConfigurationPropertySource("foo.value", "bar", "line1")); .add(new MockConfigurationPropertySource("foo.value", "bar", "line1"));
BindHandler handler = mock(BindHandler.class, BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
Bindable<JavaBean> target = Bindable.of(JavaBean.class); Bindable<JavaBean> target = Bindable.of(JavaBean.class);
this.binder.bind("foo", target, handler); this.binder.bind("foo", target, handler);
InOrder inOrder = inOrder(handler); InOrder inOrder = inOrder(handler);
......
...@@ -52,7 +52,6 @@ import static org.mockito.ArgumentMatchers.eq; ...@@ -52,7 +52,6 @@ import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isA; import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.withSettings;
/** /**
* Tests for {@link MapBinder}. * Tests for {@link MapBinder}.
...@@ -349,8 +348,7 @@ public class MapBinderTests { ...@@ -349,8 +348,7 @@ public class MapBinderTests {
@Test @Test
public void bindToMapShouldTriggerOnSuccess() { public void bindToMapShouldTriggerOnSuccess() {
this.sources.add(new MockConfigurationPropertySource("foo.bar", "1", "line1")); this.sources.add(new MockConfigurationPropertySource("foo.bar", "1", "line1"));
BindHandler handler = mock(BindHandler.class, BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
Bindable<Map<String, Integer>> target = STRING_INTEGER_MAP; Bindable<Map<String, Integer>> target = STRING_INTEGER_MAP;
this.binder.bind("foo", target, handler); this.binder.bind("foo", target, handler);
InOrder ordered = inOrder(handler); InOrder ordered = inOrder(handler);
...@@ -364,8 +362,7 @@ public class MapBinderTests { ...@@ -364,8 +362,7 @@ public class MapBinderTests {
public void bindToMapStringArrayShouldTriggerOnSuccess() { public void bindToMapStringArrayShouldTriggerOnSuccess() {
this.sources this.sources
.add(new MockConfigurationPropertySource("foo.bar", "a,b,c", "line1")); .add(new MockConfigurationPropertySource("foo.bar", "a,b,c", "line1"));
BindHandler handler = mock(BindHandler.class, BindHandler handler = mock(BindHandler.class, Answers.CALLS_REAL_METHODS);
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS));
Bindable<Map<String, String[]>> target = STRING_ARRAY_MAP; Bindable<Map<String, String[]>> target = STRING_ARRAY_MAP;
this.binder.bind("foo", target, handler); this.binder.bind("foo", target, handler);
InOrder ordered = inOrder(handler); InOrder ordered = inOrder(handler);
......
...@@ -24,7 +24,6 @@ import org.mockito.Answers; ...@@ -24,7 +24,6 @@ import org.mockito.Answers;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.withSettings;
/** /**
* Tests for {@link AliasedConfigurationPropertySource}. * Tests for {@link AliasedConfigurationPropertySource}.
...@@ -59,7 +58,7 @@ public class AliasedConfigurationPropertySourceTests { ...@@ -59,7 +58,7 @@ public class AliasedConfigurationPropertySourceTests {
public void containsDescendantOfWhenSourceReturnsUnknownShouldReturnUnknown() { public void containsDescendantOfWhenSourceReturnsUnknownShouldReturnUnknown() {
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, ConfigurationPropertySource source = mock(ConfigurationPropertySource.class,
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); Answers.CALLS_REAL_METHODS);
given(source.containsDescendantOf(name)) given(source.containsDescendantOf(name))
.willReturn(ConfigurationPropertyState.UNKNOWN); .willReturn(ConfigurationPropertyState.UNKNOWN);
ConfigurationPropertySource aliased = source ConfigurationPropertySource aliased = source
...@@ -72,7 +71,7 @@ public class AliasedConfigurationPropertySourceTests { ...@@ -72,7 +71,7 @@ public class AliasedConfigurationPropertySourceTests {
public void containsDescendantOfWhenSourceReturnsPresentShouldReturnPresent() { public void containsDescendantOfWhenSourceReturnsPresentShouldReturnPresent() {
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, ConfigurationPropertySource source = mock(ConfigurationPropertySource.class,
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); Answers.CALLS_REAL_METHODS);
given(source.containsDescendantOf(name)) given(source.containsDescendantOf(name))
.willReturn(ConfigurationPropertyState.PRESENT); .willReturn(ConfigurationPropertyState.PRESENT);
given(source.containsDescendantOf(ConfigurationPropertyName.of("bar"))) given(source.containsDescendantOf(ConfigurationPropertyName.of("bar")))
...@@ -87,7 +86,7 @@ public class AliasedConfigurationPropertySourceTests { ...@@ -87,7 +86,7 @@ public class AliasedConfigurationPropertySourceTests {
public void containsDescendantOfWhenAllAreAbsentShouldReturnAbsent() { public void containsDescendantOfWhenAllAreAbsentShouldReturnAbsent() {
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, ConfigurationPropertySource source = mock(ConfigurationPropertySource.class,
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); Answers.CALLS_REAL_METHODS);
given(source.containsDescendantOf(name)) given(source.containsDescendantOf(name))
.willReturn(ConfigurationPropertyState.ABSENT); .willReturn(ConfigurationPropertyState.ABSENT);
given(source.containsDescendantOf(ConfigurationPropertyName.of("bar"))) given(source.containsDescendantOf(ConfigurationPropertyName.of("bar")))
...@@ -102,7 +101,7 @@ public class AliasedConfigurationPropertySourceTests { ...@@ -102,7 +101,7 @@ public class AliasedConfigurationPropertySourceTests {
public void containsDescendantOfWhenAnyIsPresentShouldReturnPresent() { public void containsDescendantOfWhenAnyIsPresentShouldReturnPresent() {
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, ConfigurationPropertySource source = mock(ConfigurationPropertySource.class,
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); Answers.CALLS_REAL_METHODS);
given(source.containsDescendantOf(name)) given(source.containsDescendantOf(name))
.willReturn(ConfigurationPropertyState.ABSENT); .willReturn(ConfigurationPropertyState.ABSENT);
given(source.containsDescendantOf(ConfigurationPropertyName.of("bar"))) given(source.containsDescendantOf(ConfigurationPropertyName.of("bar")))
......
...@@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.withSettings;
/** /**
* Test for {@link FilteredIterableConfigurationPropertiesSource}. * Test for {@link FilteredIterableConfigurationPropertiesSource}.
...@@ -67,7 +66,7 @@ public class FilteredConfigurationPropertiesSourceTests { ...@@ -67,7 +66,7 @@ public class FilteredConfigurationPropertiesSourceTests {
public void containsDescendantOfWhenSourceReturnsEmptyShouldReturnEmpty() { public void containsDescendantOfWhenSourceReturnsEmptyShouldReturnEmpty() {
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, ConfigurationPropertySource source = mock(ConfigurationPropertySource.class,
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); Answers.CALLS_REAL_METHODS);
given(source.containsDescendantOf(name)) given(source.containsDescendantOf(name))
.willReturn(ConfigurationPropertyState.UNKNOWN); .willReturn(ConfigurationPropertyState.UNKNOWN);
ConfigurationPropertySource filtered = source.filter((n) -> true); ConfigurationPropertySource filtered = source.filter((n) -> true);
...@@ -79,7 +78,7 @@ public class FilteredConfigurationPropertiesSourceTests { ...@@ -79,7 +78,7 @@ public class FilteredConfigurationPropertiesSourceTests {
public void containsDescendantOfWhenSourceReturnsFalseShouldReturnFalse() { public void containsDescendantOfWhenSourceReturnsFalseShouldReturnFalse() {
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, ConfigurationPropertySource source = mock(ConfigurationPropertySource.class,
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); Answers.CALLS_REAL_METHODS);
given(source.containsDescendantOf(name)) given(source.containsDescendantOf(name))
.willReturn(ConfigurationPropertyState.ABSENT); .willReturn(ConfigurationPropertyState.ABSENT);
ConfigurationPropertySource filtered = source.filter((n) -> true); ConfigurationPropertySource filtered = source.filter((n) -> true);
...@@ -91,7 +90,7 @@ public class FilteredConfigurationPropertiesSourceTests { ...@@ -91,7 +90,7 @@ public class FilteredConfigurationPropertiesSourceTests {
public void containsDescendantOfWhenSourceReturnsTrueShouldReturnEmpty() { public void containsDescendantOfWhenSourceReturnsTrueShouldReturnEmpty() {
ConfigurationPropertyName name = ConfigurationPropertyName.of("foo"); ConfigurationPropertyName name = ConfigurationPropertyName.of("foo");
ConfigurationPropertySource source = mock(ConfigurationPropertySource.class, ConfigurationPropertySource source = mock(ConfigurationPropertySource.class,
withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS)); Answers.CALLS_REAL_METHODS);
given(source.containsDescendantOf(name)) given(source.containsDescendantOf(name))
.willReturn(ConfigurationPropertyState.PRESENT); .willReturn(ConfigurationPropertyState.PRESENT);
ConfigurationPropertySource filtered = source.filter((n) -> true); ConfigurationPropertySource filtered = source.filter((n) -> true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment