Merge pull request #14971 from dreis2211

* pr/14971:
  Polish mocks with default answer
This commit is contained in:
Phillip Webb 2018-10-26 16:42:38 -07:00
commit 621eb85ad7
5 changed files with 13 additions and 24 deletions

View File

@ -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<Integer[]> target = INTEGER_ARRAY;
this.binder.bind("foo", target, handler);
InOrder inOrder = inOrder(handler);

View File

@ -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<Integer> 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<JavaBean> target = Bindable.of(JavaBean.class);
this.binder.bind("foo", target, handler);
InOrder inOrder = inOrder(handler);

View File

@ -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<Map<String, Integer>> 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<Map<String, String[]>> target = STRING_ARRAY_MAP;
this.binder.bind("foo", target, handler);
InOrder ordered = inOrder(handler);

View File

@ -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")))

View File

@ -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);