Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,12 +35,13 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.mockito.BDDMockito.then;

/**
* Tests for {@link CloudFoundrySecurityInterceptor}.
*
* @author Madhura Bhave
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
class CloudFoundrySecurityInterceptorTests {
Expand Down Expand Up @@ -115,7 +116,7 @@ void preHandleSuccessfulWithFullAccess() {
given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(AccessLevel.FULL);
SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("test"));
ArgumentCaptor<Token> tokenArgumentCaptor = ArgumentCaptor.forClass(Token.class);
verify(this.tokenValidator).validate(tokenArgumentCaptor.capture());
then(this.tokenValidator).should().validate(tokenArgumentCaptor.capture());
Token token = tokenArgumentCaptor.getValue();
assertThat(token.toString()).isEqualTo(accessToken);
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK);
Expand All @@ -129,7 +130,7 @@ void preHandleSuccessfulWithRestrictedAccess() {
given(this.securityService.getAccessLevel(accessToken, "my-app-id")).willReturn(AccessLevel.RESTRICTED);
SecurityResponse response = this.interceptor.preHandle(this.request, EndpointId.of("info"));
ArgumentCaptor<Token> tokenArgumentCaptor = ArgumentCaptor.forClass(Token.class);
verify(this.tokenValidator).validate(tokenArgumentCaptor.capture());
then(this.tokenValidator).should().validate(tokenArgumentCaptor.capture());
Token token = tokenArgumentCaptor.getValue();
assertThat(token.toString()).isEqualTo(accessToken);
assertThat(response.getStatus()).isEqualTo(HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import org.springframework.boot.actuate.autoconfigure.cloudfoundry.CloudFoundryAuthorizationException;
Expand All @@ -46,12 +45,14 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.never;

/**
* Tests for {@link TokenValidator}.
*
* @author Madhura Bhave
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
class TokenValidatorTests {
Expand Down Expand Up @@ -109,7 +110,7 @@ void validateTokenWhenKidValidationSucceedsInTheSecondAttempt() throws Exception
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())));
verify(this.securityService).fetchTokenKeys();
then(this.securityService).should().fetchTokenKeys();
}

@Test
Expand All @@ -119,7 +120,7 @@ void validateTokenShouldFetchTokenKeysIfNull() throws Exception {
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())));
verify(this.securityService).fetchTokenKeys();
then(this.securityService).should().fetchTokenKeys();
}

@Test
Expand All @@ -129,7 +130,7 @@ void validateTokenWhenValidShouldNotFetchTokenKeys() throws Exception {
String header = "{ \"alg\": \"RS256\", \"kid\": \"valid-key\",\"typ\": \"JWT\"}";
String claims = "{ \"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\", \"scope\": [\"actuator.read\"]}";
this.tokenValidator.validate(new Token(getSignedToken(header.getBytes(), claims.getBytes())));
verify(this.securityService, Mockito.never()).fetchTokenKeys();
then(this.securityService).should(never()).fetchTokenKeys();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

/**
* Tests for {@link JmxEndpointAutoConfiguration}.
*
* @author Stephane Nicoll
* @author Yanming Zhou
*/
class JmxEndpointAutoConfigurationTests {

Expand Down Expand Up @@ -72,7 +73,7 @@ void jmxEndpointWithCustomEndpointObjectNameFactory() {
.withBean(EndpointObjectNameFactory.class, () -> factory).run((context) -> {
ArgumentCaptor<ExposableJmxEndpoint> argumentCaptor = ArgumentCaptor
.forClass(ExposableJmxEndpoint.class);
verify(factory).getObjectName(argumentCaptor.capture());
then(factory).should().getObjectName(argumentCaptor.capture());
ExposableJmxEndpoint jmxEndpoint = argumentCaptor.getValue();
assertThat(jmxEndpoint.getEndpointId().toLowerCaseString()).isEqualTo("test");
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +33,7 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.mockito.BDDMockito.then;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
Expand All @@ -46,6 +46,7 @@
* Tests for generating documentation describing {@link AuditEventsEndpoint}.
*
* @author Andy Wilkinson
* @author Yanming Zhou
*/
class AuditEventsEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {

Expand Down Expand Up @@ -83,7 +84,7 @@ void filteredAuditEvents() throws Exception {
"Restricts the events to those with the given principal. Optional."),
parameterWithName("type")
.description("Restricts the events to those with the given type. Optional."))));
verify(this.repository).find("alice", now.toInstant(), "logout");
then(this.repository).should().find("alice", now.toInstant(), "logout");
}

@Configuration(proxyBeanMethods = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,7 +40,7 @@
import org.springframework.restdocs.payload.JsonFieldType;

import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.mockito.BDDMockito.then;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.requestFields;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
Expand All @@ -52,6 +52,7 @@
* Tests for generating documentation describing the {@link LoggersEndpoint}.
*
* @author Andy Wilkinson
* @author Yanming Zhou
*/
class LoggersEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {

Expand Down Expand Up @@ -114,7 +115,7 @@ void setLogLevel() throws Exception {
.andExpect(status().isNoContent())
.andDo(MockMvcRestDocumentation.document("loggers/set", requestFields(fieldWithPath("configuredLevel")
.description("Level for the logger. May be omitted to clear the level.").optional())));
verify(this.loggingSystem).setLogLevel("com.example", LogLevel.DEBUG);
then(this.loggingSystem).should().setLogLevel("com.example", LogLevel.DEBUG);
}

@Test
Expand All @@ -127,8 +128,8 @@ void setLogLevelOfLoggerGroup() throws Exception {
requestFields(fieldWithPath("configuredLevel").description(
"Level for the logger group. May be omitted to clear the level of the loggers.")
.optional())));
verify(this.loggingSystem).setLogLevel("test.member1", LogLevel.DEBUG);
verify(this.loggingSystem).setLogLevel("test.member2", LogLevel.DEBUG);
then(this.loggingSystem).should().setLogLevel("test.member1", LogLevel.DEBUG);
then(this.loggingSystem).should().setLogLevel("test.member2", LogLevel.DEBUG);
resetLogger();
}

Expand All @@ -142,7 +143,7 @@ void clearLogLevel() throws Exception {
this.mockMvc
.perform(post("/actuator/loggers/com.example").content("{}").contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isNoContent()).andDo(MockMvcRestDocumentation.document("loggers/clear"));
verify(this.loggingSystem).setLogLevel("com.example", null);
then(this.loggingSystem).should().setLogLevel("com.example", null);
}

@Configuration(proxyBeanMethods = false)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,7 @@
import org.springframework.test.context.TestPropertySource;

import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import static org.mockito.BDDMockito.then;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
Expand All @@ -52,6 +52,7 @@
* Tests for generating documentation describing the {@link ShutdownEndpoint}.
*
* @author Andy Wilkinson
* @author Yanming Zhou
*/
@TestPropertySource(properties = "spring.jackson.serialization.write-dates-as-timestamps=false")
class SessionsEndpointDocumentationTests extends MockMvcEndpointDocumentationTests {
Expand Down Expand Up @@ -102,7 +103,7 @@ void sessionWithId() throws Exception {
void deleteASession() throws Exception {
this.mockMvc.perform(delete("/actuator/sessions/{id}", sessionTwo.getId())).andExpect(status().isNoContent())
.andDo(document("sessions/delete"));
verify(this.sessionRepository).deleteById(sessionTwo.getId());
then(this.sessionRepository).should().deleteById(sessionTwo.getId());
}

private static MapSession createSession(Instant creationTime, Instant lastAccessedTime) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -35,16 +35,16 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;

/**
* Tests for {@link MeterRegistryConfigurer}.
*
* @author Phillip Webb
* @author Andy Wilkinson
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
class MeterRegistryConfigurerTests {
Expand Down Expand Up @@ -77,7 +77,7 @@ void configureWhenCompositeShouldApplyCustomizer() {
createObjectProvider(this.filters), createObjectProvider(this.binders), false, false);
CompositeMeterRegistry composite = new CompositeMeterRegistry();
configurer.configure(composite);
verify(this.mockCustomizer).customize(composite);
then(this.mockCustomizer).should().customize(composite);
}

@Test
Expand All @@ -87,7 +87,7 @@ void configureShouldApplyCustomizer() {
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers),
createObjectProvider(this.filters), createObjectProvider(this.binders), false, false);
configurer.configure(this.mockRegistry);
verify(this.mockCustomizer).customize(this.mockRegistry);
then(this.mockCustomizer).should().customize(this.mockRegistry);
}

@Test
Expand All @@ -97,7 +97,7 @@ void configureShouldApplyFilter() {
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers),
createObjectProvider(this.filters), createObjectProvider(this.binders), false, false);
configurer.configure(this.mockRegistry);
verify(this.mockConfig).meterFilter(this.mockFilter);
then(this.mockConfig).should().meterFilter(this.mockFilter);
}

@Test
Expand All @@ -107,7 +107,7 @@ void configureShouldApplyBinder() {
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers),
createObjectProvider(this.filters), createObjectProvider(this.binders), false, false);
configurer.configure(this.mockRegistry);
verify(this.mockBinder).bindTo(this.mockRegistry);
then(this.mockBinder).should().bindTo(this.mockRegistry);
}

@Test
Expand All @@ -117,7 +117,7 @@ void configureShouldApplyBinderToComposite() {
createObjectProvider(this.filters), createObjectProvider(this.binders), false, true);
CompositeMeterRegistry composite = new CompositeMeterRegistry();
configurer.configure(composite);
verify(this.mockBinder).bindTo(composite);
then(this.mockBinder).should().bindTo(composite);
}

@Test
Expand All @@ -126,7 +126,7 @@ void configureShouldNotApplyBinderWhenCompositeExists() {
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(createObjectProvider(this.customizers),
createObjectProvider(this.filters), null, false, true);
configurer.configure(this.mockRegistry);
verifyNoInteractions(this.mockBinder);
then(this.mockBinder).shouldHaveNoInteractions();
}

@Test
Expand All @@ -139,9 +139,9 @@ void configureShouldBeCalledInOrderCustomizerFilterBinder() {
createObjectProvider(this.filters), createObjectProvider(this.binders), false, false);
configurer.configure(this.mockRegistry);
InOrder ordered = inOrder(this.mockBinder, this.mockConfig, this.mockCustomizer);
ordered.verify(this.mockCustomizer).customize(this.mockRegistry);
ordered.verify(this.mockConfig).meterFilter(this.mockFilter);
ordered.verify(this.mockBinder).bindTo(this.mockRegistry);
then(this.mockCustomizer).should(ordered).customize(this.mockRegistry);
then(this.mockConfig).should(ordered).meterFilter(this.mockFilter);
then(this.mockBinder).should(ordered).bindTo(this.mockRegistry);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,13 +33,14 @@
import org.springframework.test.util.ReflectionTestUtils;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

/**
* Tests for {@link MetricsAutoConfiguration}.
*
* @author Andy Wilkinson
* @author Yanming Zhou
*/
class MetricsAutoConfigurationTests {

Expand Down Expand Up @@ -67,8 +68,8 @@ void configuresMeterRegistries() {
assertThat(filters[0].accept((Meter.Id) null)).isEqualTo(MeterFilterReply.DENY);
assertThat(filters[1]).isInstanceOf(PropertiesMeterFilter.class);
assertThat(filters[2].accept((Meter.Id) null)).isEqualTo(MeterFilterReply.ACCEPT);
verify((MeterBinder) context.getBean("meterBinder")).bindTo(meterRegistry);
verify(context.getBean(MeterRegistryCustomizer.class)).customize(meterRegistry);
then((MeterBinder) context.getBean("meterBinder")).should().bindTo(meterRegistry);
then(context.getBean(MeterRegistryCustomizer.class)).should().customize(meterRegistry);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import org.springframework.util.function.SingletonSupplier;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

/**
* Tests for {@link MetricsRepositoryMethodInvocationListenerBeanPostProcessor} .
*
* @author Phillip Webb
* @author Yanming Zhou
*/
class MetricsRepositoryMethodInvocationListenerBeanPostProcessorTests {

Expand All @@ -49,10 +50,10 @@ void postProcessBeforeInitializationWhenRepositoryFactoryBeanSupportAddsListener
assertThat(result).isSameAs(bean);
ArgumentCaptor<RepositoryFactoryCustomizer> customizer = ArgumentCaptor
.forClass(RepositoryFactoryCustomizer.class);
verify(bean).addRepositoryFactoryCustomizer(customizer.capture());
then(bean).should().addRepositoryFactoryCustomizer(customizer.capture());
RepositoryFactorySupport repositoryFactory = mock(RepositoryFactorySupport.class);
customizer.getValue().customize(repositoryFactory);
verify(repositoryFactory).addInvocationListener(this.listener);
then(repositoryFactory).should().addInvocationListener(this.listener);
}

@Test
Expand Down
Loading