Skip to content

Commit

Permalink
Increase JUnit5 usage (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek authored Oct 20, 2021
1 parent 3beb53a commit 95ce587
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 151 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package org.springframework.cloud.client.discovery;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

Expand All @@ -43,7 +43,7 @@ public class EnableDiscoveryClientImportSelectorTests {
@Mock
private AnnotationAttributes annotationAttributes;

@Before
@BeforeEach
public void setup() {
MockitoAnnotations.initMocks(this);
this.importSelector.setBeanClassLoader(getClass().getClassLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package org.springframework.cloud.client.hypermedia;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.hateoas.Link;
Expand All @@ -32,6 +32,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -40,7 +41,7 @@
* @author Oliver Gierke
* @author Tim Ysewyn
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class DiscoveredResourceUnitTests {

@Mock
Expand All @@ -57,9 +58,9 @@ public class DiscoveredResourceUnitTests {

DiscoveredResource resource;

@Before
@BeforeEach
public void setUp() {
when(this.traversal.buildTraversal(any(Traverson.class))).thenReturn(this.builder);
lenient().when(this.traversal.buildTraversal(any(Traverson.class))).thenReturn(this.builder);

this.resource = new DiscoveredResource(this.provider, this.traversal);
this.resource.setRestOperations(this.operations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

import java.util.Arrays;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
Expand All @@ -34,7 +34,7 @@
/**
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class DynamicServiceInstanceProviderUnitTests {

@Mock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@
import java.util.Arrays;
import java.util.Map;

import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.jupiter.api.Test;

import org.springframework.beans.factory.BeanCreationException;
import org.springframework.boot.test.util.TestPropertyValues;
Expand All @@ -32,16 +29,14 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;

import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.BDDAssertions.then;

/**
* @author Spencer Gibb
*/
public class AutoServiceRegistrationAutoConfigurationTests {

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void hasAutoServiceRegistration() {
try (AnnotationConfigApplicationContext context = setup(HasAutoServiceRegistrationConfiguration.class)) {
Expand All @@ -52,12 +47,12 @@ public void hasAutoServiceRegistration() {

@Test
public void noAutoServiceRegistrationAndFailFast() {
this.exception.expect(BeanCreationException.class);
this.exception.expectMessage(Matchers.containsString("no AutoServiceRegistration"));
try (AnnotationConfigApplicationContext context = setup(
"spring.cloud.service-registry.auto-registration.failFast=true")) {
assertNoBean(context);
}
assertThatThrownBy(() -> {
try (AnnotationConfigApplicationContext context = setup(
"spring.cloud.service-registry.auto-registration.failFast=true")) {
assertNoBean(context);
}
}).isInstanceOf(BeanCreationException.class).hasMessageContaining("no AutoServiceRegistration");
}

@Test
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.springframework.cloud.loadbalancer.core;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

Expand All @@ -36,7 +35,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.reactive.function.client.WebClient;

import static java.time.Duration.ofMillis;
Expand All @@ -49,7 +47,6 @@
* @author Olga Maciaszek-Sharma
*/
@SpringBootTest(classes = CachingServiceInstanceListSupplierTests.TestConfig.class)
@ExtendWith(SpringExtension.class)
class CachingServiceInstanceListSupplierTests {

public static final String SERVICE_ID = "test";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
Expand All @@ -44,7 +43,6 @@
import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties;
import org.springframework.cloud.loadbalancer.support.ServiceInstanceListSuppliers;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
Expand All @@ -67,7 +65,6 @@
* @author Roman Chigvintsev
* @author Sabyasachi Bhattacharya
*/
@ExtendWith(SpringExtension.class)
@SpringBootTest(classes = HealthCheckServiceInstanceListSupplierTests.TestApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class HealthCheckServiceInstanceListSupplierTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.springframework.cloud.loadbalancer.core;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.cloud.client.discovery.ReactiveDiscoveryClient;
Expand All @@ -27,7 +27,7 @@
import org.springframework.web.reactive.function.client.WebClient;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.mock;

public class ServiceInstanceListSupplierBuilderTests {
Expand Down

0 comments on commit 95ce587

Please sign in to comment.