#76 - Upgrade to JUnit 5.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2019 the original author or authors.
|
||||
* Copyright 2008-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.
|
||||
@@ -15,16 +15,14 @@
|
||||
*/
|
||||
package org.springframework.plugin.core;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.plugin.core.PluginRegistry.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.Order;
|
||||
@@ -35,14 +33,14 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class OrderAwarePluginRegistryUnitTest extends SimplePluginRegistryUnitTest {
|
||||
class OrderAwarePluginRegistryUnitTest extends SimplePluginRegistryUnitTest {
|
||||
|
||||
TestPlugin firstPlugin;
|
||||
TestPlugin secondPlugin;
|
||||
|
||||
@Override
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
super.setUp();
|
||||
|
||||
@@ -51,14 +49,14 @@ public class OrderAwarePluginRegistryUnitTest extends SimplePluginRegistryUnitTe
|
||||
}
|
||||
|
||||
@Test
|
||||
public void honorsOrderOnAddPlugins() throws Exception {
|
||||
void honorsOrderOnAddPlugins() throws Exception {
|
||||
|
||||
PluginRegistry<TestPlugin, String> registry = of(firstPlugin, secondPlugin);
|
||||
assertOrder(registry, secondPlugin, firstPlugin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createsRevertedRegistryCorrectly() throws Exception {
|
||||
void createsRevertedRegistryCorrectly() throws Exception {
|
||||
|
||||
OrderAwarePluginRegistry<TestPlugin, String> registry = OrderAwarePluginRegistry.of(firstPlugin, secondPlugin);
|
||||
PluginRegistry<TestPlugin, String> reverse = registry.reverse();
|
||||
@@ -71,7 +69,7 @@ public class OrderAwarePluginRegistryUnitTest extends SimplePluginRegistryUnitTe
|
||||
* @see #1
|
||||
*/
|
||||
@Test
|
||||
public void considersJdkProxiedOrderedImplementation() {
|
||||
void considersJdkProxiedOrderedImplementation() {
|
||||
|
||||
ThirdImplementation plugin = new ThirdImplementation();
|
||||
TestPlugin thirdPlugin = (TestPlugin) new ProxyFactory(plugin).getProxy();
|
||||
@@ -84,37 +82,37 @@ public class OrderAwarePluginRegistryUnitTest extends SimplePluginRegistryUnitTe
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultSetupUsesDefaultComparator() {
|
||||
void defaultSetupUsesDefaultComparator() {
|
||||
assertDefaultComparator(OrderAwarePluginRegistry.empty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultSetupUsesDefaultReverseComparator() {
|
||||
void defaultSetupUsesDefaultReverseComparator() {
|
||||
|
||||
OrderAwarePluginRegistry<Plugin<Object>, Object> registry = OrderAwarePluginRegistry
|
||||
.ofReverse(Collections.emptyList());
|
||||
Object field = ReflectionTestUtils.getField(registry, "comparator");
|
||||
|
||||
assertThat(field, is(ReflectionTestUtils.getField(registry, "DEFAULT_REVERSE_COMPARATOR")));
|
||||
assertThat(field).isEqualTo(ReflectionTestUtils.getField(registry, "DEFAULT_REVERSE_COMPARATOR"));
|
||||
}
|
||||
|
||||
private static void assertOrder(PluginRegistry<TestPlugin, String> registry, TestPlugin... plugins) {
|
||||
|
||||
List<TestPlugin> result = registry.getPluginsFor("delimiter");
|
||||
|
||||
assertThat(plugins.length, is(result.size()));
|
||||
assertThat(plugins.length).isEqualTo(result.size());
|
||||
|
||||
for (int i = 0; i < plugins.length; i++) {
|
||||
assertThat(result.get(i), is(plugins[i]));
|
||||
assertThat(result.get(i)).isEqualTo(plugins[i]);
|
||||
}
|
||||
|
||||
assertThat(registry.getPluginFor("delimiter"), is(Optional.of(plugins[0])));
|
||||
assertThat(registry.getPluginFor("delimiter")).hasValue(plugins[0]);
|
||||
}
|
||||
|
||||
private static void assertDefaultComparator(OrderAwarePluginRegistry<?, ?> registry) {
|
||||
|
||||
Object field = ReflectionTestUtils.getField(registry, "comparator");
|
||||
assertThat(field, is(ReflectionTestUtils.getField(registry, "DEFAULT_COMPARATOR")));
|
||||
assertThat(field).isEqualTo(ReflectionTestUtils.getField(registry, "DEFAULT_COMPARATOR"));
|
||||
}
|
||||
|
||||
private static interface TestPlugin extends Plugin<String> {
|
||||
|
||||
@@ -15,12 +15,9 @@
|
||||
*/
|
||||
package org.springframework.plugin.core;
|
||||
|
||||
import org.springframework.plugin.core.Plugin;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public interface SamplePlugin extends Plugin<String> {
|
||||
|
||||
void pluginMethod();
|
||||
}
|
||||
|
||||
@@ -15,37 +15,32 @@
|
||||
*/
|
||||
package org.springframework.plugin.core;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit test for {@link SimplePluginRegistry}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimplePluginRegistryUnitTest {
|
||||
class SimplePluginRegistryUnitTest {
|
||||
|
||||
SamplePlugin plugin;
|
||||
|
||||
SimplePluginRegistry<SamplePlugin, String> registry;
|
||||
|
||||
public @Rule ExpectedException o_O = ExpectedException.none();
|
||||
|
||||
/**
|
||||
* Initializes a {@code PluginRegistry} and equips it with an {@code EmailNotificationProvider}.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
plugin = new SamplePluginImplementation();
|
||||
registry = SimplePluginRegistry.empty();
|
||||
@@ -57,117 +52,111 @@ public class SimplePluginRegistryUnitTest {
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void assertRegistryInitialized() throws Exception {
|
||||
void assertRegistryInitialized() throws Exception {
|
||||
|
||||
registry = SimplePluginRegistry.of(plugin);
|
||||
|
||||
assertThat(registry.countPlugins(), is(1));
|
||||
assertTrue(registry.contains(plugin));
|
||||
assertThat(registry.countPlugins()).isEqualTo(1);
|
||||
assertThat(registry.contains(plugin)).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts asking for a plugin with the {@code PluginMetadata} provided by the {@link EmailNotificationProvider}.
|
||||
*/
|
||||
@Test
|
||||
public void assertFindsEmailNotificationProvider() {
|
||||
void assertFindsEmailNotificationProvider() {
|
||||
|
||||
registry = SimplePluginRegistry.of(plugin);
|
||||
|
||||
String delimiter = "FOO";
|
||||
|
||||
List<SamplePlugin> plugins = registry.getPluginsFor(delimiter);
|
||||
assertThat(plugins, is(notNullValue()));
|
||||
assertThat(plugins.size(), is(1));
|
||||
assertThat(plugins).isNotNull();
|
||||
assertThat(plugins).hasSize(1);
|
||||
|
||||
SamplePlugin provider = plugins.get(0);
|
||||
assertThat(provider, is(instanceOf(SamplePluginImplementation.class)));
|
||||
assertThat(provider).isInstanceOf(SamplePluginImplementation.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the given exception to be thrown if no {@link Plugin} found.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void throwsExceptionIfNoPluginFound() {
|
||||
@Test
|
||||
void throwsExceptionIfNoPluginFound() {
|
||||
|
||||
registry.getPluginFor("BAR", () -> new IllegalArgumentException());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> registry.getPluginFor("BAR", () -> new IllegalArgumentException()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expects the given exception to be thrown if no {@link Plugin}s found.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void throwsExceptionIfNoPluginsFound() {
|
||||
@Test
|
||||
void throwsExceptionIfNoPluginsFound() {
|
||||
|
||||
registry.getPluginsFor("BAR", () -> new IllegalArgumentException());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> registry.getPluginsFor("BAR", () -> new IllegalArgumentException()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Expect the defualt plugin to be returned if none found.
|
||||
*/
|
||||
@Test
|
||||
public void returnsDefaultIfNoneFound() {
|
||||
void returnsDefaultIfNoneFound() {
|
||||
|
||||
SamplePlugin defaultPlugin = new SamplePluginImplementation();
|
||||
|
||||
assertThat(registry.getPluginOrDefaultFor("BAR", defaultPlugin), is(defaultPlugin));
|
||||
assertThat(registry.getPluginOrDefaultFor("BAR", defaultPlugin)).isEqualTo(defaultPlugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expect the given default plugins to be returned if none found.
|
||||
*/
|
||||
@Test
|
||||
public void returnsDefaultsIfNoneFound() {
|
||||
void returnsDefaultsIfNoneFound() {
|
||||
|
||||
List<? extends SamplePlugin> defaultPlugins = Arrays.asList(new SamplePluginImplementation());
|
||||
|
||||
List<SamplePlugin> result = registry.getPluginsFor("BAR", defaultPlugins);
|
||||
assertTrue(result.containsAll(defaultPlugins));
|
||||
assertThat(result).containsAll(defaultPlugins);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesAddingNullPluginsCorrecty() throws Exception {
|
||||
void handlesAddingNullPluginsCorrecty() throws Exception {
|
||||
|
||||
List<SamplePlugin> plugins = new ArrayList<SamplePlugin>();
|
||||
plugins.add(null);
|
||||
|
||||
registry = SimplePluginRegistry.of(plugins);
|
||||
|
||||
assertThat(registry.countPlugins(), is(0));
|
||||
assertThat(registry.countPlugins()).isEqualTo(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #19
|
||||
*/
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void throwsExceptionFromSupplier() throws Exception {
|
||||
@Test // #19
|
||||
void throwsExceptionFromSupplier() throws Exception {
|
||||
|
||||
registry = SimplePluginRegistry.empty();
|
||||
|
||||
registry.getPluginFor("FOO", () -> new IllegalStateException());
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> registry.getPluginFor("FOO", () -> new IllegalStateException()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #41
|
||||
*/
|
||||
public void throwsExceptionIfRequiredPluginIsNotFound() {
|
||||
@Test // #41
|
||||
void throwsExceptionIfRequiredPluginIsNotFound() {
|
||||
|
||||
registry = SimplePluginRegistry.empty();
|
||||
|
||||
o_O.expect(IllegalArgumentException.class);
|
||||
|
||||
registry.getRequiredPluginFor("FOO");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> registry.getRequiredPluginFor("FOO"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #41
|
||||
*/
|
||||
public void throwsExceptionWithMessafeIfRequiredPluginIsNotFound() {
|
||||
@Test // #41
|
||||
void throwsExceptionWithMessafeIfRequiredPluginIsNotFound() {
|
||||
|
||||
registry = SimplePluginRegistry.of(Collections.emptyList());
|
||||
|
||||
o_O.expect(IllegalArgumentException.class);
|
||||
o_O.expectMessage("message");
|
||||
|
||||
registry.getRequiredPluginFor("FOO", () -> "message");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> registry.getRequiredPluginFor("FOO", () -> "message"))
|
||||
.withMessage("message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 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.
|
||||
@@ -15,11 +15,10 @@
|
||||
*/
|
||||
package org.springframework.plugin.core.config;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -29,16 +28,16 @@ import org.springframework.plugin.core.PluginRegistry;
|
||||
import org.springframework.plugin.core.SamplePlugin;
|
||||
import org.springframework.plugin.core.SamplePluginImplementation;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link EnablePluginRegistries}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class EnablePluginRegistriesIntegrationTest {
|
||||
@ExtendWith(SpringExtension.class)
|
||||
class EnablePluginRegistriesIntegrationTest {
|
||||
|
||||
@Configuration
|
||||
@EnablePluginRegistries({ SamplePlugin.class, AnotherPlugin.class })
|
||||
@@ -53,8 +52,8 @@ public class EnablePluginRegistriesIntegrationTest {
|
||||
@Autowired PluginRegistry<SamplePlugin, String> registry;
|
||||
|
||||
@Test
|
||||
public void registersPluginRegistries() {
|
||||
assertThat(registry, is(notNullValue()));
|
||||
void registersPluginRegistries() {
|
||||
assertThat(registry).isNotNull();
|
||||
}
|
||||
|
||||
@Qualifier("myQualifier")
|
||||
|
||||
@@ -15,56 +15,48 @@
|
||||
*/
|
||||
package org.springframework.plugin.core.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.plugin.core.PluginRegistry;
|
||||
import org.springframework.plugin.core.SamplePlugin;
|
||||
import org.springframework.plugin.core.SamplePluginHost;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
/**
|
||||
* Integration test to simply check if the configuration gets parsed correctly.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration(locations = "classpath:application-context.xml")
|
||||
public class PluginConfigurationIntegrationTest {
|
||||
class PluginConfigurationIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
List<SamplePlugin> samplePlugins;
|
||||
@Autowired List<SamplePlugin> samplePlugins;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("bar")
|
||||
PluginRegistry<SamplePlugin, String> pluginRegistry;
|
||||
@Autowired @Qualifier("bar") PluginRegistry<SamplePlugin, String> pluginRegistry;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("host")
|
||||
SamplePluginHost host;
|
||||
@Autowired @Qualifier("host") SamplePluginHost host;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("otherHost")
|
||||
SamplePluginHost otherHost;
|
||||
@Autowired @Qualifier("otherHost") SamplePluginHost otherHost;
|
||||
|
||||
@Autowired
|
||||
SamplePlugin plugin;
|
||||
@Autowired SamplePlugin plugin;
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
void test() throws Exception {
|
||||
|
||||
assertNotNull(samplePlugins);
|
||||
assertThat(samplePlugins).isNotNull();
|
||||
|
||||
assertSame(pluginRegistry, host.getRegistry());
|
||||
assertNotSame(pluginRegistry, otherHost.getRegistry());
|
||||
assertThat(pluginRegistry).isSameAs(host.getRegistry());
|
||||
assertThat(pluginRegistry).isNotSameAs(otherHost.getRegistry());
|
||||
|
||||
assertTrue(samplePlugins.contains(plugin));
|
||||
assertTrue(pluginRegistry.contains(plugin));
|
||||
assertThat(samplePlugins).contains(plugin);
|
||||
assertThat(pluginRegistry).contains(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2012 the original author or authors.
|
||||
* Copyright 2008-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.
|
||||
@@ -15,34 +15,34 @@
|
||||
*/
|
||||
package org.springframework.plugin.core.support;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.runners.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.Ordered;
|
||||
|
||||
/**
|
||||
* Unit test for {@link BeanListFactoryBean}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BeanListFactoryBeanUnitTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class BeanListFactoryBeanUnitTest {
|
||||
|
||||
BeanListFactoryBean<Ordered> factory;
|
||||
|
||||
@Mock ApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
|
||||
factory = new BeanListFactoryBean<Ordered>();
|
||||
factory.setApplicationContext(context);
|
||||
@@ -52,7 +52,7 @@ public class BeanListFactoryBeanUnitTest {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void regardsOrderOfBeans() throws Exception {
|
||||
void regardsOrderOfBeans() throws Exception {
|
||||
|
||||
// They shall be switched in the result.
|
||||
Ordered first = () -> 5;
|
||||
@@ -64,28 +64,20 @@ public class BeanListFactoryBeanUnitTest {
|
||||
when(context.getBean("second")).thenReturn(second);
|
||||
|
||||
Object result = factory.getObject();
|
||||
assertTrue(result instanceof List<?>);
|
||||
assertThat(result).isInstanceOfSatisfying(List.class, it -> {
|
||||
|
||||
List<Ordered> members = type(result);
|
||||
|
||||
assertEquals(0, members.indexOf(second));
|
||||
assertEquals(1, members.indexOf(first));
|
||||
assertThat(it.indexOf(second)).isEqualByComparingTo(0);
|
||||
assertThat(it.indexOf(first)).isEqualTo(1);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void returnsEmptyListIfNoBeansFound() throws Exception {
|
||||
|
||||
when(context.getBeanNamesForType(Ordered.class, false, false)).thenReturn(new String[0]);
|
||||
|
||||
Object result = factory.getObject();
|
||||
assertTrue(result instanceof List<?>);
|
||||
|
||||
List<Ordered> members = type(result);
|
||||
assertTrue(members.isEmpty());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> List<T> type(Object list) {
|
||||
return (List<T>) list;
|
||||
assertThat(result).isInstanceOfSatisfying(List.class, it -> assertThat(it).isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package org.springframework.plugin.core.support;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -18,16 +16,16 @@ import org.springframework.plugin.core.OrderAwarePluginRegistry;
|
||||
import org.springframework.plugin.core.Plugin;
|
||||
import org.springframework.plugin.core.config.EnablePluginRegistries;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
/**
|
||||
* Integration test for {@link OrderAwarePluginRegistry}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration
|
||||
public class OrderAwarePluginRegistryIntegrationTest {
|
||||
class OrderAwarePluginRegistryIntegrationTest {
|
||||
|
||||
@Configuration
|
||||
@EnablePluginRegistries(TestPlugin.class)
|
||||
@@ -49,34 +47,29 @@ public class OrderAwarePluginRegistryIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
ApplicationContext context;
|
||||
@Autowired ApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
FirstImplementation first;
|
||||
@Autowired
|
||||
SecondImplementation second;
|
||||
@Autowired
|
||||
ThirdImplementation third;
|
||||
@Autowired FirstImplementation first;
|
||||
@Autowired SecondImplementation second;
|
||||
@Autowired ThirdImplementation third;
|
||||
|
||||
@Autowired
|
||||
OrderAwarePluginRegistry<TestPlugin, String> registry;
|
||||
@Autowired OrderAwarePluginRegistry<TestPlugin, String> registry;
|
||||
|
||||
@Test
|
||||
public void considersJdkProxiedOrderedImplementation() {
|
||||
void considersJdkProxiedOrderedImplementation() {
|
||||
|
||||
List<TestPlugin> plugins = registry.getPlugins();
|
||||
|
||||
assertThat(plugins, Matchers.hasSize(3));
|
||||
assertThat(plugins.get(0), is((TestPlugin) second));
|
||||
assertThat(plugins.get(1), is((TestPlugin) third));
|
||||
assertThat(plugins.get(2), is((TestPlugin) first));
|
||||
assertThat(plugins).hasSize(3);
|
||||
assertThat(plugins.get(0)).isEqualTo(second);
|
||||
assertThat(plugins.get(1)).isEqualTo(third);
|
||||
assertThat(plugins.get(2)).isEqualTo(first);
|
||||
|
||||
plugins = registry.reverse().getPlugins();
|
||||
|
||||
assertThat(plugins.get(2), is((TestPlugin) second));
|
||||
assertThat(plugins.get(1), is((TestPlugin) third));
|
||||
assertThat(plugins.get(0), is((TestPlugin) first));
|
||||
assertThat(plugins.get(2)).isEqualTo(second);
|
||||
assertThat(plugins.get(1)).isEqualTo(third);
|
||||
assertThat(plugins.get(0)).isEqualTo(first);
|
||||
}
|
||||
|
||||
private static interface TestPlugin extends Plugin<String> {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Copyright 2015-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. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
@@ -15,37 +15,36 @@
|
||||
*/
|
||||
package org.springframework.plugin.metadata;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SimplePluginMetadata}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class SimplePluginMetadataUnitTest {
|
||||
class SimplePluginMetadataUnitTest {
|
||||
|
||||
/**
|
||||
* @see #11
|
||||
*/
|
||||
@Test
|
||||
public void equalsIsWorkingCorrectly() {
|
||||
void equalsIsWorkingCorrectly() {
|
||||
|
||||
SimplePluginMetadata nameOneOh = new SimplePluginMetadata("Name", "1.0");
|
||||
SimplePluginMetadata sameNameOneOh = new SimplePluginMetadata("Name", "1.0");
|
||||
SimplePluginMetadata nameTwoOh = new SimplePluginMetadata("Name", "2.0");
|
||||
SimplePluginMetadata anotherNameOneOh = new SimplePluginMetadata("AnotherName", "1.0");
|
||||
|
||||
assertThat(nameOneOh, is(nameOneOh));
|
||||
assertThat(nameOneOh, is(sameNameOneOh));
|
||||
assertThat(sameNameOneOh, is(nameOneOh));
|
||||
assertThat(nameOneOh).isEqualTo(nameOneOh);
|
||||
assertThat(nameOneOh).isEqualTo(sameNameOneOh);
|
||||
assertThat(sameNameOneOh).isEqualTo(nameOneOh);
|
||||
|
||||
assertThat(nameOneOh, is(not(nameTwoOh)));
|
||||
assertThat(nameTwoOh, is(not(nameOneOh)));
|
||||
assertThat(nameOneOh).isNotEqualTo(nameTwoOh);
|
||||
assertThat(nameTwoOh).isNotEqualTo(nameOneOh);
|
||||
|
||||
assertThat(nameOneOh, is(not(anotherNameOneOh)));
|
||||
assertThat(anotherNameOneOh, is(not(nameOneOh)));
|
||||
assertThat(nameOneOh).isNotEqualTo(anotherNameOneOh);
|
||||
assertThat(anotherNameOneOh).isNotEqualTo(nameOneOh);
|
||||
}
|
||||
}
|
||||
|
||||
35
pom.xml
35
pom.xml
@@ -45,8 +45,13 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<assertj.version>3.20.2</assertj.version>
|
||||
<junit.version>5.8.0</junit.version>
|
||||
<mockito.version>3.12.4</mockito.version>
|
||||
<spring.version>5.2.0.RELEASE</spring.version>
|
||||
<slf4j.version>1.7.25</slf4j.version>
|
||||
|
||||
<java-module-name>spring.plugin</java-module-name>
|
||||
</properties>
|
||||
|
||||
@@ -240,16 +245,30 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.8.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-all</artifactId>
|
||||
<version>1.10.19</version>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<version>${mockito.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -288,6 +307,12 @@
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user