@@ -60,11 +60,10 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
|
||||
@@ -16,21 +16,21 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.commons;
|
||||
|
||||
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.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Ryan Baxter
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
|
||||
classes = KubernetesCommonsAutoConfigurationTests.App.class,
|
||||
properties = { "spring.cloud.kubernetes.client.password=mypassword",
|
||||
|
||||
@@ -18,31 +18,39 @@ package org.springframework.cloud.kubernetes.commons;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInfo;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class LazilyInstantiateTest {
|
||||
|
||||
private static final String TAG = "excluded-from-before";
|
||||
|
||||
private static final String SINGLETON = "singleton";
|
||||
|
||||
@Mock
|
||||
private Supplier<String> mockSupplier;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// common setup
|
||||
when(this.mockSupplier.get()).thenReturn(SINGLETON)
|
||||
.thenThrow(new RuntimeException("Supplier was called more than once!"));
|
||||
@BeforeEach
|
||||
public void setUp(TestInfo testInfo) throws Exception {
|
||||
// some tests do not need this mocking
|
||||
if (!testInfo.getTags().contains(TAG)) {
|
||||
// common setup
|
||||
when(this.mockSupplier.get()).thenReturn(SINGLETON)
|
||||
.thenThrow(new RuntimeException("Supplier was called more than once!"));
|
||||
}
|
||||
}
|
||||
|
||||
@Tag(TAG)
|
||||
@Test
|
||||
public void supplierNotCalledInLazyInstantiateFactoryMethod() {
|
||||
LazilyInstantiate.using(this.mockSupplier);
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.commons.config.reload.condition;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
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.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
@@ -30,7 +30,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class EventReloadDetectionModeTest {
|
||||
|
||||
private static final String RELOAD_PROPERTY = "spring.cloud.kubernetes.reload.mode";
|
||||
@@ -55,7 +55,7 @@ public class EventReloadDetectionModeTest {
|
||||
Mockito.when(environment.containsProperty(RELOAD_PROPERTY)).thenReturn(true);
|
||||
Mockito.when(environment.getProperty(RELOAD_PROPERTY)).thenReturn(null);
|
||||
boolean matches = underTest.matches(context, metadata);
|
||||
Assert.assertFalse(matches);
|
||||
Assertions.assertFalse(matches);
|
||||
}
|
||||
|
||||
// lack of this property being set, means a match.
|
||||
@@ -64,7 +64,7 @@ public class EventReloadDetectionModeTest {
|
||||
Mockito.when(context.getEnvironment()).thenReturn(environment);
|
||||
Mockito.when(environment.containsProperty(RELOAD_PROPERTY)).thenReturn(false);
|
||||
boolean matches = underTest.matches(context, metadata);
|
||||
Assert.assertTrue(matches);
|
||||
Assertions.assertTrue(matches);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +73,7 @@ public class EventReloadDetectionModeTest {
|
||||
Mockito.when(environment.containsProperty(RELOAD_PROPERTY)).thenReturn(true);
|
||||
Mockito.when(environment.getProperty(RELOAD_PROPERTY)).thenReturn("EVENT");
|
||||
boolean matches = underTest.matches(context, metadata);
|
||||
Assert.assertTrue(matches);
|
||||
Assertions.assertTrue(matches);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +82,7 @@ public class EventReloadDetectionModeTest {
|
||||
Mockito.when(environment.containsProperty(RELOAD_PROPERTY)).thenReturn(true);
|
||||
Mockito.when(environment.getProperty(RELOAD_PROPERTY)).thenReturn("eVeNt");
|
||||
boolean matches = underTest.matches(context, metadata);
|
||||
Assert.assertTrue(matches);
|
||||
Assertions.assertTrue(matches);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,7 +91,7 @@ public class EventReloadDetectionModeTest {
|
||||
Mockito.when(environment.containsProperty(RELOAD_PROPERTY)).thenReturn(true);
|
||||
Mockito.when(environment.getProperty(RELOAD_PROPERTY)).thenReturn("not-eVeNt");
|
||||
boolean matches = underTest.matches(context, metadata);
|
||||
Assert.assertFalse(matches);
|
||||
Assertions.assertFalse(matches);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
package org.springframework.cloud.kubernetes.commons.config.reload.condition;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
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.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import org.springframework.context.annotation.ConditionContext;
|
||||
import org.springframework.core.env.Environment;
|
||||
@@ -30,7 +30,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
|
||||
/**
|
||||
* @author wind57
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class PollingReloadDetectionModeTest {
|
||||
|
||||
private static final String RELOAD_PROPERTY = "spring.cloud.kubernetes.reload.mode";
|
||||
@@ -55,7 +55,7 @@ public class PollingReloadDetectionModeTest {
|
||||
Mockito.when(environment.containsProperty(RELOAD_PROPERTY)).thenReturn(true);
|
||||
Mockito.when(environment.getProperty(RELOAD_PROPERTY)).thenReturn(null);
|
||||
boolean matches = underTest.matches(context, metadata);
|
||||
Assert.assertFalse(matches);
|
||||
Assertions.assertFalse(matches);
|
||||
}
|
||||
|
||||
// lack of this property being set, means a NO match (unlike EventReloadDetectionMode)
|
||||
@@ -64,7 +64,7 @@ public class PollingReloadDetectionModeTest {
|
||||
Mockito.when(context.getEnvironment()).thenReturn(environment);
|
||||
Mockito.when(environment.containsProperty(RELOAD_PROPERTY)).thenReturn(false);
|
||||
boolean matches = underTest.matches(context, metadata);
|
||||
Assert.assertFalse(matches);
|
||||
Assertions.assertFalse(matches);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +73,7 @@ public class PollingReloadDetectionModeTest {
|
||||
Mockito.when(environment.containsProperty(RELOAD_PROPERTY)).thenReturn(true);
|
||||
Mockito.when(environment.getProperty(RELOAD_PROPERTY)).thenReturn("POLLING");
|
||||
boolean matches = underTest.matches(context, metadata);
|
||||
Assert.assertTrue(matches);
|
||||
Assertions.assertTrue(matches);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +82,7 @@ public class PollingReloadDetectionModeTest {
|
||||
Mockito.when(environment.containsProperty(RELOAD_PROPERTY)).thenReturn(true);
|
||||
Mockito.when(environment.getProperty(RELOAD_PROPERTY)).thenReturn("PoLLiNG");
|
||||
boolean matches = underTest.matches(context, metadata);
|
||||
Assert.assertTrue(matches);
|
||||
Assertions.assertTrue(matches);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,7 +91,7 @@ public class PollingReloadDetectionModeTest {
|
||||
Mockito.when(environment.containsProperty(RELOAD_PROPERTY)).thenReturn(true);
|
||||
Mockito.when(environment.getProperty(RELOAD_PROPERTY)).thenReturn("not-POLLING");
|
||||
boolean matches = underTest.matches(context, metadata);
|
||||
Assert.assertFalse(matches);
|
||||
Assertions.assertFalse(matches);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,10 +22,10 @@ import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.MockedStatic;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
@@ -67,13 +67,13 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
}
|
||||
};
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
paths = Mockito.mockStatic(Paths.class);
|
||||
files = Mockito.mockStatic(Files.class);
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void after() {
|
||||
paths.close();
|
||||
files.close();
|
||||
@@ -178,16 +178,16 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
* 'kubernetes' profile is not present
|
||||
*/
|
||||
private void assertKubernetesProfileNotPresent() {
|
||||
Assert.assertFalse("'kubernetes' profile must not be present when 'spring.cloud.kubernetes.enabled' is false",
|
||||
kubernetesProfile().isPresent());
|
||||
Assertions.assertFalse(kubernetesProfile().isPresent(),
|
||||
"'kubernetes' profile must not be present when 'spring.cloud.kubernetes.enabled' is false");
|
||||
}
|
||||
|
||||
/*
|
||||
* 'kubernetes' profile is present
|
||||
*/
|
||||
private void assertKubernetesProfilePresent() {
|
||||
Assert.assertTrue("'kubernetes' profile must be present when 'spring.cloud.kubernetes.enabled' is true",
|
||||
kubernetesProfile().isPresent());
|
||||
Assertions.assertTrue(kubernetesProfile().isPresent(),
|
||||
"'kubernetes' profile must be present when 'spring.cloud.kubernetes.enabled' is true");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -196,9 +196,8 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
private void assertKubernetesPropertySourceNotPresent() {
|
||||
Optional<PropertySource<?>> kubernetesPropertySource = kubernetesPropertySource();
|
||||
|
||||
Assert.assertFalse(
|
||||
"'KUBERNETES_NAMESPACE_PROPERTY_SOURCE' source must not be present when 'spring.cloud.kubernetes.enabled' is false",
|
||||
kubernetesPropertySource.isPresent());
|
||||
Assertions.assertFalse(kubernetesPropertySource.isPresent(),
|
||||
"'KUBERNETES_NAMESPACE_PROPERTY_SOURCE' source must not be present when 'spring.cloud.kubernetes.enabled' is false");
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -207,13 +206,13 @@ public class AbstractKubernetesProfileEnvironmentPostProcessorTest {
|
||||
private void assertKubernetesPropertySourcePresent() {
|
||||
|
||||
Optional<PropertySource<?>> kubernetesPropertySource = kubernetesPropertySource();
|
||||
Assert.assertTrue(
|
||||
"'KUBERNETES_NAMESPACE_PROPERTY_SOURCE' source must be present when 'spring.cloud.kubernetes.enabled' is true",
|
||||
kubernetesPropertySource.isPresent());
|
||||
Assertions.assertTrue(kubernetesPropertySource.isPresent(),
|
||||
"'KUBERNETES_NAMESPACE_PROPERTY_SOURCE' source must be present when 'spring.cloud.kubernetes.enabled' is true");
|
||||
|
||||
String property = (String) kubernetesPropertySource.get()
|
||||
.getProperty("spring.cloud.kubernetes.client.namespace");
|
||||
Assert.assertEquals("'spring.cloud.kubernetes.client.namespace' must be set to 'foundIt'", property, FOUNT_IT);
|
||||
Assertions.assertEquals(property, FOUNT_IT,
|
||||
"'spring.cloud.kubernetes.client.namespace' must be set to 'foundIt'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user