Polish "Replace Mockito argument captors with assertArg"
Co-authored-by: Andy Wilkinson <wilkinsona@vmware.com> See gh-35015
This commit is contained in:
@@ -28,7 +28,6 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Captor;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.boot.DefaultBootstrapContext;
|
||||
@@ -77,9 +76,6 @@ class ConfigDataEnvironmentContributorsTests {
|
||||
|
||||
private ConfigDataActivationContext activationContext;
|
||||
|
||||
@Captor
|
||||
private ArgumentCaptor<ConfigDataLocationResolverContext> locationResolverContext;
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
this.environment = new MockEnvironment();
|
||||
@@ -213,10 +209,12 @@ class ConfigDataEnvironmentContributorsTests {
|
||||
ConfigDataEnvironmentContributor contributor = ConfigDataEnvironmentContributor.ofInitialImport(LOCATION_1);
|
||||
ConfigDataEnvironmentContributors contributors = new ConfigDataEnvironmentContributors(this.logFactory,
|
||||
this.bootstrapContext, Arrays.asList(contributor));
|
||||
ArgumentCaptor<ConfigDataLocationResolverContext> locationResolverContext = ArgumentCaptor
|
||||
.forClass(ConfigDataLocationResolverContext.class);
|
||||
contributors.withProcessedImports(this.importer, this.activationContext);
|
||||
then(this.importer).should()
|
||||
.resolveAndLoad(any(), this.locationResolverContext.capture(), any(), eq(secondLocations));
|
||||
ConfigDataLocationResolverContext context = this.locationResolverContext.getValue();
|
||||
.resolveAndLoad(any(), locationResolverContext.capture(), any(), eq(secondLocations));
|
||||
ConfigDataLocationResolverContext context = locationResolverContext.getValue();
|
||||
assertThat(context.getParent()).hasToString("a");
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.util.Properties;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InOrder;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
@@ -49,6 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.entry;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.assertArg;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -348,11 +348,9 @@ class MapBinderTests {
|
||||
Bindable<Map<String, String[]>> target = STRING_ARRAY_MAP;
|
||||
this.binder.bind("foo", target, handler);
|
||||
InOrder ordered = inOrder(handler);
|
||||
ArgumentCaptor<String[]> array = ArgumentCaptor.forClass(String[].class);
|
||||
ordered.verify(handler)
|
||||
.onSuccess(eq(ConfigurationPropertyName.of("foo.bar")), eq(Bindable.of(String[].class)), any(),
|
||||
array.capture());
|
||||
assertThat(array.getValue()).containsExactly("a", "b", "c");
|
||||
assertArg((array) -> assertThat((String[]) array).containsExactly("a", "b", "c")));
|
||||
ordered.verify(handler).onSuccess(eq(ConfigurationPropertyName.of("foo")), eq(target), any(), isA(Map.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import ch.qos.logback.core.model.processor.ModelHandlerException;
|
||||
import ch.qos.logback.core.model.processor.ModelInterpretationContext;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.Profiles;
|
||||
@@ -59,14 +59,14 @@ class SpringProfileModelHandlerTests {
|
||||
SpringProfileModel model = new SpringProfileModel();
|
||||
model.setName("dev");
|
||||
this.action.handle(this.interpretationContext, model);
|
||||
ArgumentCaptor<Profiles> profiles = ArgumentCaptor.forClass(Profiles.class);
|
||||
then(this.environment).should().acceptsProfiles(profiles.capture());
|
||||
List<String> profileNames = new ArrayList<>();
|
||||
profiles.getValue().matches((profile) -> {
|
||||
profileNames.add(profile);
|
||||
return false;
|
||||
});
|
||||
assertThat(profileNames).containsExactly("dev");
|
||||
then(this.environment).should().acceptsProfiles(ArgumentMatchers.<Profiles>assertArg(((profiles) -> {
|
||||
List<String> profileNames = new ArrayList<>();
|
||||
profiles.matches((profile) -> {
|
||||
profileNames.add(profile);
|
||||
return false;
|
||||
});
|
||||
assertThat(profileNames).containsExactly("dev");
|
||||
})));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,14 +74,14 @@ class SpringProfileModelHandlerTests {
|
||||
SpringProfileModel model = new SpringProfileModel();
|
||||
model.setName("dev,qa");
|
||||
this.action.handle(this.interpretationContext, model);
|
||||
ArgumentCaptor<Profiles> profiles = ArgumentCaptor.forClass(Profiles.class);
|
||||
then(this.environment).should().acceptsProfiles(profiles.capture());
|
||||
List<String> profileNames = new ArrayList<>();
|
||||
profiles.getValue().matches((profile) -> {
|
||||
profileNames.add(profile);
|
||||
return false;
|
||||
});
|
||||
assertThat(profileNames).containsExactly("dev", "qa");
|
||||
then(this.environment).should().acceptsProfiles(ArgumentMatchers.<Profiles>assertArg(((profiles) -> {
|
||||
List<String> profileNames = new ArrayList<>();
|
||||
profiles.matches((profile) -> {
|
||||
profileNames.add(profile);
|
||||
return false;
|
||||
});
|
||||
assertThat(profileNames).containsExactly("dev", "qa");
|
||||
})));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,14 +90,14 @@ class SpringProfileModelHandlerTests {
|
||||
model.setName("${profile}");
|
||||
this.context.putProperty("profile", "dev");
|
||||
this.action.handle(this.interpretationContext, model);
|
||||
ArgumentCaptor<Profiles> profiles = ArgumentCaptor.forClass(Profiles.class);
|
||||
then(this.environment).should().acceptsProfiles(profiles.capture());
|
||||
List<String> profileNames = new ArrayList<>();
|
||||
profiles.getValue().matches((profile) -> {
|
||||
profileNames.add(profile);
|
||||
return false;
|
||||
});
|
||||
assertThat(profileNames).containsExactly("dev");
|
||||
then(this.environment).should().acceptsProfiles(ArgumentMatchers.<Profiles>assertArg(((profiles) -> {
|
||||
List<String> profileNames = new ArrayList<>();
|
||||
profiles.matches((profile) -> {
|
||||
profileNames.add(profile);
|
||||
return false;
|
||||
});
|
||||
assertThat(profileNames).containsExactly("dev");
|
||||
})));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,14 +108,14 @@ class SpringProfileModelHandlerTests {
|
||||
this.context.putProperty("profile1", "dev");
|
||||
this.context.putProperty("profile2", "qa");
|
||||
this.action.handle(this.interpretationContext, model);
|
||||
ArgumentCaptor<Profiles> profiles = ArgumentCaptor.forClass(Profiles.class);
|
||||
then(this.environment).should().acceptsProfiles(profiles.capture());
|
||||
List<String> profileNames = new ArrayList<>();
|
||||
profiles.getValue().matches((profile) -> {
|
||||
profileNames.add(profile);
|
||||
return false;
|
||||
});
|
||||
assertThat(profileNames).containsExactly("dev", "qa");
|
||||
then(this.environment).should().acceptsProfiles(ArgumentMatchers.<Profiles>assertArg(((profiles) -> {
|
||||
List<String> profileNames = new ArrayList<>();
|
||||
profiles.matches((profile) -> {
|
||||
profileNames.add(profile);
|
||||
return false;
|
||||
});
|
||||
assertThat(profileNames).containsExactly("dev", "qa");
|
||||
})));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user