Search in sources :

Example 51 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project spring-security by spring-projects.

the class SwitchUserWebFilterTests method switchUser.

@Test
public void switchUser() {
    final String targetUsername = "TEST_USERNAME";
    final UserDetails switchUserDetails = switchUserDetails(targetUsername, true);
    final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/login/impersonate?username={targetUser}", targetUsername));
    final WebFilterChain chain = mock(WebFilterChain.class);
    final Authentication originalAuthentication = new UsernamePasswordAuthenticationToken("principal", "credentials");
    final SecurityContextImpl securityContext = new SecurityContextImpl(originalAuthentication);
    given(this.userDetailsService.findByUsername(targetUsername)).willReturn(Mono.just(switchUserDetails));
    given(this.serverSecurityContextRepository.save(eq(exchange), any(SecurityContext.class))).willReturn(Mono.empty());
    given(this.successHandler.onAuthenticationSuccess(any(WebFilterExchange.class), any(Authentication.class))).willReturn(Mono.empty());
    this.switchUserWebFilter.filter(exchange, chain).subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext))).block();
    verifyNoInteractions(chain);
    verify(this.userDetailsService).findByUsername(targetUsername);
    final ArgumentCaptor<SecurityContext> securityContextCaptor = ArgumentCaptor.forClass(SecurityContext.class);
    verify(this.serverSecurityContextRepository).save(eq(exchange), securityContextCaptor.capture());
    final SecurityContext savedSecurityContext = securityContextCaptor.getValue();
    final ArgumentCaptor<Authentication> authenticationCaptor = ArgumentCaptor.forClass(Authentication.class);
    verify(this.successHandler).onAuthenticationSuccess(any(WebFilterExchange.class), authenticationCaptor.capture());
    final Authentication switchUserAuthentication = authenticationCaptor.getValue();
    assertThat(switchUserAuthentication).isSameAs(savedSecurityContext.getAuthentication());
    assertThat(switchUserAuthentication.getName()).isEqualTo(targetUsername);
    assertThat(switchUserAuthentication.getAuthorities()).anyMatch(SwitchUserGrantedAuthority.class::isInstance);
    assertThat(switchUserAuthentication.getAuthorities()).anyMatch((a) -> a.getAuthority().contains(SwitchUserWebFilter.ROLE_PREVIOUS_ADMINISTRATOR));
    assertThat(switchUserAuthentication.getAuthorities().stream().filter((a) -> a instanceof SwitchUserGrantedAuthority).map((a) -> ((SwitchUserGrantedAuthority) a).getSource()).map(Principal::getName)).contains(originalAuthentication.getName());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) ServerWebExchangeMatcher(org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) WebFilterExchange(org.springframework.security.web.server.WebFilterExchange) ArgumentCaptor(org.mockito.ArgumentCaptor) ReactiveSecurityContextHolder(org.springframework.security.core.context.ReactiveSecurityContextHolder) ReactiveUserDetailsService(org.springframework.security.core.userdetails.ReactiveUserDetailsService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BDDMockito.given(org.mockito.BDDMockito.given) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) DisabledException(org.springframework.security.authentication.DisabledException) UserDetails(org.springframework.security.core.userdetails.UserDetails) AuthenticationCredentialsNotFoundException(org.springframework.security.authentication.AuthenticationCredentialsNotFoundException) WebSessionServerSecurityContextRepository(org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository) WebFilterChain(org.springframework.web.server.WebFilterChain) ServerSecurityContextRepository(org.springframework.security.web.server.context.ServerSecurityContextRepository) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Context(reactor.util.context.Context) HttpMethod(org.springframework.http.HttpMethod) ServerWebExchangeMatchers(org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mono(reactor.core.publisher.Mono) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Principal(java.security.Principal) SwitchUserGrantedAuthority(org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority) SecurityContext(org.springframework.security.core.context.SecurityContext) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) AccountStatusUserDetailsChecker(org.springframework.security.authentication.AccountStatusUserDetailsChecker) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Authentication(org.springframework.security.core.Authentication) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) WebFilterExchange(org.springframework.security.web.server.WebFilterExchange) SwitchUserGrantedAuthority(org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority) UserDetails(org.springframework.security.core.userdetails.UserDetails) WebFilterChain(org.springframework.web.server.WebFilterChain) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) Principal(java.security.Principal) Test(org.junit.jupiter.api.Test)

Example 52 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project spring-security by spring-projects.

the class SwitchUserWebFilterTests method switchUserWhenUserAlreadySwitchedThenExitSwitchAndSwitchAgain.

@Test
public void switchUserWhenUserAlreadySwitchedThenExitSwitchAndSwitchAgain() {
    final Authentication originalAuthentication = new UsernamePasswordAuthenticationToken("origPrincipal", "origCredentials");
    final GrantedAuthority switchAuthority = new SwitchUserGrantedAuthority(SwitchUserWebFilter.ROLE_PREVIOUS_ADMINISTRATOR, originalAuthentication);
    final Authentication switchUserAuthentication = new UsernamePasswordAuthenticationToken("switchPrincipal", "switchCredentials", Collections.singleton(switchAuthority));
    final SecurityContextImpl securityContext = new SecurityContextImpl(switchUserAuthentication);
    final String targetUsername = "newSwitchPrincipal";
    final MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.post("/login/impersonate?username={targetUser}", targetUsername));
    final WebFilterChain chain = mock(WebFilterChain.class);
    given(this.serverSecurityContextRepository.save(eq(exchange), any(SecurityContext.class))).willReturn(Mono.empty());
    given(this.successHandler.onAuthenticationSuccess(any(WebFilterExchange.class), any(Authentication.class))).willReturn(Mono.empty());
    given(this.userDetailsService.findByUsername(targetUsername)).willReturn(Mono.just(switchUserDetails(targetUsername, true)));
    this.switchUserWebFilter.filter(exchange, chain).subscriberContext(ReactiveSecurityContextHolder.withSecurityContext(Mono.just(securityContext))).block();
    final ArgumentCaptor<Authentication> authenticationCaptor = ArgumentCaptor.forClass(Authentication.class);
    verify(this.successHandler).onAuthenticationSuccess(any(WebFilterExchange.class), authenticationCaptor.capture());
    final Authentication secondSwitchUserAuthentication = authenticationCaptor.getValue();
    assertThat(secondSwitchUserAuthentication.getName()).isEqualTo(targetUsername);
    assertThat(secondSwitchUserAuthentication.getAuthorities().stream().filter((a) -> a instanceof SwitchUserGrantedAuthority).map((a) -> ((SwitchUserGrantedAuthority) a).getSource()).map(Principal::getName).findFirst().orElse(null)).isEqualTo(originalAuthentication.getName());
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) ServerWebExchangeMatcher(org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) User(org.springframework.security.core.userdetails.User) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) WebFilterExchange(org.springframework.security.web.server.WebFilterExchange) ArgumentCaptor(org.mockito.ArgumentCaptor) ReactiveSecurityContextHolder(org.springframework.security.core.context.ReactiveSecurityContextHolder) ReactiveUserDetailsService(org.springframework.security.core.userdetails.ReactiveUserDetailsService) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) BDDMockito.given(org.mockito.BDDMockito.given) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) DisabledException(org.springframework.security.authentication.DisabledException) UserDetails(org.springframework.security.core.userdetails.UserDetails) AuthenticationCredentialsNotFoundException(org.springframework.security.authentication.AuthenticationCredentialsNotFoundException) WebSessionServerSecurityContextRepository(org.springframework.security.web.server.context.WebSessionServerSecurityContextRepository) WebFilterChain(org.springframework.web.server.WebFilterChain) ServerSecurityContextRepository(org.springframework.security.web.server.context.ServerSecurityContextRepository) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) MockServerHttpRequest(org.springframework.mock.http.server.reactive.MockServerHttpRequest) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) Context(reactor.util.context.Context) HttpMethod(org.springframework.http.HttpMethod) ServerWebExchangeMatchers(org.springframework.security.web.server.util.matcher.ServerWebExchangeMatchers) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mono(reactor.core.publisher.Mono) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) Principal(java.security.Principal) SwitchUserGrantedAuthority(org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority) SecurityContext(org.springframework.security.core.context.SecurityContext) Assertions.assertThatIllegalArgumentException(org.assertj.core.api.Assertions.assertThatIllegalArgumentException) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) AccountStatusUserDetailsChecker(org.springframework.security.authentication.AccountStatusUserDetailsChecker) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Authentication(org.springframework.security.core.Authentication) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) SecurityContextImpl(org.springframework.security.core.context.SecurityContextImpl) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) GrantedAuthority(org.springframework.security.core.GrantedAuthority) SwitchUserGrantedAuthority(org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) MockServerWebExchange(org.springframework.mock.web.server.MockServerWebExchange) SwitchUserGrantedAuthority(org.springframework.security.web.authentication.switchuser.SwitchUserGrantedAuthority) WebFilterExchange(org.springframework.security.web.server.WebFilterExchange) WebFilterChain(org.springframework.web.server.WebFilterChain) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) Principal(java.security.Principal) Test(org.junit.jupiter.api.Test)

Example 53 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project storm by apache.

the class KafkaSpoutEmitTest method testSpoutWillSkipPartitionsAtTheMaxUncommittedOffsetsLimit.

@Test
public void testSpoutWillSkipPartitionsAtTheMaxUncommittedOffsetsLimit() {
    // This verifies that partitions can't prevent each other from retrying tuples due to the maxUncommittedOffsets limit.
    try (SimulatedTime simulatedTime = new SimulatedTime()) {
        TopicPartition partitionTwo = new TopicPartition(SingleTopicKafkaSpoutConfiguration.TOPIC, 2);
        KafkaSpout<String, String> spout = SpoutWithMockedConsumerSetupHelper.setupSpout(spoutConfig, conf, contextMock, collectorMock, consumerMock, partition, partitionTwo);
        Map<TopicPartition, List<ConsumerRecord<String, String>>> records = new HashMap<>();
        // This is cheating a bit since maxPollRecords would normally spread this across multiple polls
        records.put(partition, SpoutWithMockedConsumerSetupHelper.createRecords(partition, 0, spoutConfig.getMaxUncommittedOffsets()));
        records.put(partitionTwo, SpoutWithMockedConsumerSetupHelper.createRecords(partitionTwo, 0, spoutConfig.getMaxUncommittedOffsets() + 1));
        int numMessages = spoutConfig.getMaxUncommittedOffsets() * 2 + 1;
        when(consumerMock.poll(anyLong())).thenReturn(new ConsumerRecords<>(records));
        for (int i = 0; i < numMessages; i++) {
            spout.nextTuple();
        }
        ArgumentCaptor<KafkaSpoutMessageId> messageIds = ArgumentCaptor.forClass(KafkaSpoutMessageId.class);
        verify(collectorMock, times(numMessages)).emit(anyString(), anyList(), messageIds.capture());
        // Now fail a tuple on partition one and verify that it is allowed to retry, because the failed tuple is below the maxUncommittedOffsets limit
        Optional<KafkaSpoutMessageId> failedMessageIdPartitionOne = messageIds.getAllValues().stream().filter(messageId -> messageId.partition() == partition.partition()).findAny();
        spout.fail(failedMessageIdPartitionOne.get());
        // Also fail the last tuple from partition two. Since the failed tuple is beyond the maxUncommittedOffsets limit, it should not be retried until earlier messages are acked.
        Optional<KafkaSpoutMessageId> failedMessagePartitionTwo = messageIds.getAllValues().stream().filter(messageId -> messageId.partition() == partitionTwo.partition()).max((msgId, msgId2) -> (int) (msgId.offset() - msgId2.offset()));
        spout.fail(failedMessagePartitionTwo.get());
        reset(collectorMock);
        Time.advanceTime(50);
        when(consumerMock.poll(anyLong())).thenReturn(new ConsumerRecords<>(Collections.singletonMap(partition, SpoutWithMockedConsumerSetupHelper.createRecords(partition, failedMessageIdPartitionOne.get().offset(), 1))));
        spout.nextTuple();
        verify(collectorMock, times(1)).emit(anyObject(), anyObject(), anyObject());
        InOrder inOrder = inOrder(consumerMock);
        inOrder.verify(consumerMock).seek(partition, failedMessageIdPartitionOne.get().offset());
        // Should not seek on the paused partition
        inOrder.verify(consumerMock, never()).seek(eq(partitionTwo), anyLong());
        inOrder.verify(consumerMock).pause(Collections.singleton(partitionTwo));
        inOrder.verify(consumerMock).poll(anyLong());
        inOrder.verify(consumerMock).resume(Collections.singleton(partitionTwo));
        reset(collectorMock);
        // Now also check that no more tuples are polled for, since both partitions are at their limits
        spout.nextTuple();
        verify(collectorMock, never()).emit(anyObject(), anyObject(), anyObject());
    }
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) SingleTopicKafkaSpoutConfiguration(org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration) SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ManualPartitioner(org.apache.storm.kafka.spout.subscription.ManualPartitioner) TopologyContext(org.apache.storm.task.TopologyContext) HashMap(java.util.HashMap) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) SingleTopicKafkaSpoutConfiguration.createKafkaSpoutConfigBuilder(org.apache.storm.kafka.spout.config.builder.SingleTopicKafkaSpoutConfiguration.createKafkaSpoutConfigBuilder) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) Map(java.util.Map) TopicPartition(org.apache.kafka.common.TopicPartition) InOrder(org.mockito.InOrder) ArgumentMatchers.anyObject(org.mockito.ArgumentMatchers.anyObject) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) Mockito.verify(org.mockito.Mockito.verify) Time(org.apache.storm.utils.Time) Test(org.junit.jupiter.api.Test) Mockito.never(org.mockito.Mockito.never) List(java.util.List) TopicFilter(org.apache.storm.kafka.spout.subscription.TopicFilter) Mockito.inOrder(org.mockito.Mockito.inOrder) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Optional(java.util.Optional) SpoutOutputCollector(org.apache.storm.spout.SpoutOutputCollector) Mockito.reset(org.mockito.Mockito.reset) Collections(java.util.Collections) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KafkaConsumer(org.apache.kafka.clients.consumer.KafkaConsumer) Mockito.mock(org.mockito.Mockito.mock) SimulatedTime(org.apache.storm.utils.Time.SimulatedTime) InOrder(org.mockito.InOrder) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TopicPartition(org.apache.kafka.common.TopicPartition) ArrayList(java.util.ArrayList) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 54 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project storm by apache.

the class ProcessorBoltTest method testEmitAndAck.

@Test
public void testEmitAndAck() throws Exception {
    setUpProcessorBolt(new FilterProcessor<Integer>(x -> true));
    bolt.execute(mockTuple1);
    ArgumentCaptor<Collection> anchor = ArgumentCaptor.forClass(Collection.class);
    ArgumentCaptor<Values> values = ArgumentCaptor.forClass(Values.class);
    ArgumentCaptor<String> os = ArgumentCaptor.forClass(String.class);
    Mockito.verify(mockOutputCollector).emit(os.capture(), anchor.capture(), values.capture());
    assertEquals("outputstream", os.getValue());
    assertArrayEquals(new Object[] { mockTuple1 }, anchor.getValue().toArray());
    assertEquals(new Values(100), values.getValue());
    Mockito.verify(mockOutputCollector, Mockito.times(1)).ack(mockTuple1);
}
Also used : LongSum(org.apache.storm.streams.operations.aggregators.LongSum) TopologyContext(org.apache.storm.task.TopologyContext) HashMap(java.util.HashMap) Multimap(org.apache.storm.shade.com.google.common.collect.Multimap) DefaultDirectedGraph(org.apache.storm.shade.org.jgrapht.graph.DefaultDirectedGraph) Values(org.apache.storm.tuple.Values) Tuple(org.apache.storm.tuple.Tuple) ArgumentCaptor(org.mockito.ArgumentCaptor) OutputCollector(org.apache.storm.task.OutputCollector) Map(java.util.Map) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Before(org.junit.Before) FilterProcessor(org.apache.storm.streams.processors.FilterProcessor) DirectedGraph(org.apache.storm.shade.org.jgrapht.DirectedGraph) Collection(java.util.Collection) Grouping(org.apache.storm.generated.Grouping) Set(java.util.Set) Test(org.junit.Test) Fields(org.apache.storm.tuple.Fields) GlobalStreamId(org.apache.storm.generated.GlobalStreamId) AggregateProcessor(org.apache.storm.streams.processors.AggregateProcessor) Processor(org.apache.storm.streams.processors.Processor) Mockito(org.mockito.Mockito) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Values(org.apache.storm.tuple.Values) Collection(java.util.Collection) Test(org.junit.Test)

Example 55 with ArgumentCaptor

use of org.mockito.ArgumentCaptor in project dropwizard by dropwizard.

the class HealthCheckManagerTest method shouldNotChangeServerStateWhenNonCriticalHealthCheckRecovers.

@Test
void shouldNotChangeServerStateWhenNonCriticalHealthCheckRecovers() {
    final List<HealthCheckConfiguration> configs = new ArrayList<>();
    final HealthCheckConfiguration nonCriticalConfig = new HealthCheckConfiguration();
    nonCriticalConfig.setName(NAME);
    nonCriticalConfig.setCritical(false);
    nonCriticalConfig.setSchedule(new Schedule());
    configs.add(nonCriticalConfig);
    final HealthCheckConfiguration criticalConfig = new HealthCheckConfiguration();
    criticalConfig.setName(NAME_2);
    criticalConfig.setCritical(true);
    criticalConfig.setSchedule(new Schedule());
    configs.add(criticalConfig);
    final HealthCheckManager manager = new HealthCheckManager(unmodifiableList(configs), scheduler, new MetricRegistry(), SHUTDOWN_WAIT, true, Collections.emptyList());
    final HealthCheck check = mock(HealthCheck.class);
    manager.onHealthCheckAdded(NAME, check);
    manager.onHealthCheckAdded(NAME_2, check);
    manager.onStateChanged(NAME, false);
    manager.onStateChanged(NAME_2, false);
    assertThat(manager.isHealthy()).isFalse();
    manager.onStateChanged(NAME, true);
    assertThat(manager.isHealthy()).isFalse();
    ArgumentCaptor<ScheduledHealthCheck> checkCaptor = ArgumentCaptor.forClass(ScheduledHealthCheck.class);
    ArgumentCaptor<Boolean> healthyCaptor = ArgumentCaptor.forClass(Boolean.class);
    verify(scheduler, times(2)).scheduleInitial(checkCaptor.capture());
    verify(scheduler, times(3)).schedule(checkCaptor.capture(), healthyCaptor.capture());
    assertThat(checkCaptor.getAllValues()).hasSize(5).satisfies(values -> assertThat(values).element(0).satisfies(value -> assertThat(value.getName()).isEqualTo(NAME)).satisfies(value -> assertThat(value.isCritical()).isFalse())).satisfies(values -> assertThat(values).element(1).satisfies(value -> assertThat(value.getName()).isEqualTo(NAME_2)).satisfies(value -> assertThat(value.isCritical()).isTrue())).satisfies(values -> assertThat(values).element(2).satisfies(value -> assertThat(value.getName()).isEqualTo(NAME)).satisfies(value -> assertThat(value.isCritical()).isFalse())).satisfies(values -> assertThat(values).element(3).satisfies(value -> assertThat(value.getName()).isEqualTo(NAME_2)).satisfies(value -> assertThat(value.isCritical()).isTrue())).satisfies(values -> assertThat(values).element(4).satisfies(value -> assertThat(value.getName()).isEqualTo(NAME)).satisfies(value -> assertThat(value.isCritical()).isFalse()));
    assertThat(healthyCaptor.getAllValues()).containsExactly(false, false, true);
}
Also used : Collections.unmodifiableList(java.util.Collections.unmodifiableList) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory(org.slf4j.LoggerFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DisabledOnOs(org.junit.jupiter.api.condition.DisabledOnOs) Duration(io.dropwizard.util.Duration) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Counter(com.codahale.metrics.Counter) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Collections.singletonMap(java.util.Collections.singletonMap) Maps(io.dropwizard.util.Maps) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) OS(org.junit.jupiter.api.condition.OS) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Mockito.times(org.mockito.Mockito.times) HealthCheck(com.codahale.metrics.health.HealthCheck) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) Collections(java.util.Collections) Mockito.mock(org.mockito.Mockito.mock) MetricRegistry(com.codahale.metrics.MetricRegistry) ArrayList(java.util.ArrayList) HealthCheck(com.codahale.metrics.health.HealthCheck) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.jupiter.api.Test)

Aggregations

ArgumentCaptor (org.mockito.ArgumentCaptor)231 Mockito.verify (org.mockito.Mockito.verify)156 List (java.util.List)128 Test (org.junit.Test)116 Mockito.mock (org.mockito.Mockito.mock)113 Mockito.when (org.mockito.Mockito.when)100 Test (org.junit.jupiter.api.Test)86 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)85 Mockito (org.mockito.Mockito)85 Map (java.util.Map)76 BeforeEach (org.junit.jupiter.api.BeforeEach)72 Arrays (java.util.Arrays)69 Collectors (java.util.stream.Collectors)69 Collections (java.util.Collections)68 Before (org.junit.Before)65 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)64 Mockito.times (org.mockito.Mockito.times)64 ArrayList (java.util.ArrayList)60 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)60 Mockito.never (org.mockito.Mockito.never)58