|
|
|
@ -16,20 +16,21 @@
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.hamcrest.Description;
|
|
|
|
|
import org.hamcrest.Matcher;
|
|
|
|
|
import org.hamcrest.core.IsEqual;
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.rules.ExpectedException;
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurationSorter;
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
|
import org.springframework.core.io.DefaultResourceLoader;
|
|
|
|
|
|
|
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
|
|
import static org.junit.Assert.assertThat;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -37,7 +38,7 @@ import static org.junit.Assert.assertThat;
|
|
|
|
|
*
|
|
|
|
|
* @author Phillip Webb
|
|
|
|
|
*/
|
|
|
|
|
public class AutoConfigurationSorterTest {
|
|
|
|
|
public class AutoConfigurationSorterTests {
|
|
|
|
|
|
|
|
|
|
private static final String LOWEST = OrderLowest.class.getName();
|
|
|
|
|
private static final String HIGHEST = OrderHighest.class.getName();
|
|
|
|
@ -45,6 +46,11 @@ public class AutoConfigurationSorterTest {
|
|
|
|
|
private static final String B = AutoConfigureB.class.getName();
|
|
|
|
|
private static final String C = AutoConfigureC.class.getName();
|
|
|
|
|
private static final String D = AutoConfigureD.class.getName();
|
|
|
|
|
private static final String E = AutoConfigureE.class.getName();
|
|
|
|
|
private static final String W = AutoConfigureW.class.getName();
|
|
|
|
|
private static final String X = AutoConfigureX.class.getName();
|
|
|
|
|
private static final String Y = AutoConfigureY.class.getName();
|
|
|
|
|
private static final String Z = AutoConfigureZ.class.getName();
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
|
public ExpectedException thrown = ExpectedException.none();
|
|
|
|
@ -60,19 +66,38 @@ public class AutoConfigurationSorterTest {
|
|
|
|
|
public void byOrderAnnotation() throws Exception {
|
|
|
|
|
List<String> actual = this.sorter.getInPriorityOrder(Arrays.asList(LOWEST,
|
|
|
|
|
HIGHEST));
|
|
|
|
|
assertThat(actual, equalTo(Arrays.asList(HIGHEST, LOWEST)));
|
|
|
|
|
assertThat(actual, nameMatcher(HIGHEST, LOWEST));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void byAutoConfigureAfter() throws Exception {
|
|
|
|
|
List<String> actual = this.sorter.getInPriorityOrder(Arrays.asList(A, B, C));
|
|
|
|
|
assertThat(actual, equalTo(Arrays.asList(C, B, A)));
|
|
|
|
|
assertThat(actual, nameMatcher(C, B, A));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void byAutoConfigureBefore() throws Exception {
|
|
|
|
|
List<String> actual = this.sorter.getInPriorityOrder(Arrays.asList(X, Y, Z));
|
|
|
|
|
assertThat(actual, nameMatcher(Z, Y, X));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void byAutoConfigureAfterDoubles() throws Exception {
|
|
|
|
|
List<String> actual = this.sorter.getInPriorityOrder(Arrays.asList(A, B, C, E));
|
|
|
|
|
assertThat(actual, nameMatcher(C, E, B, A));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void byAutoConfigureMixedBeforeAndAfter() throws Exception {
|
|
|
|
|
List<String> actual = this.sorter
|
|
|
|
|
.getInPriorityOrder(Arrays.asList(A, B, C, W, X));
|
|
|
|
|
assertThat(actual, nameMatcher(C, W, B, A, X));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void byAutoConfigureAfterWithMissing() throws Exception {
|
|
|
|
|
List<String> actual = this.sorter.getInPriorityOrder(Arrays.asList(A, B));
|
|
|
|
|
assertThat(actual, equalTo(Arrays.asList(B, A)));
|
|
|
|
|
assertThat(actual, nameMatcher(B, A));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@ -82,6 +107,39 @@ public class AutoConfigurationSorterTest {
|
|
|
|
|
this.sorter.getInPriorityOrder(Arrays.asList(A, B, C, D));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Matcher<? super List<String>> nameMatcher(String... names) {
|
|
|
|
|
|
|
|
|
|
final List<String> list = Arrays.asList(names);
|
|
|
|
|
|
|
|
|
|
return new IsEqual<List<String>>(list) {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void describeMismatch(Object item, Description description) {
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
List<String> items = (List<String>) item;
|
|
|
|
|
description.appendText("was ").appendValue(prettify(items));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void describeTo(Description description) {
|
|
|
|
|
description.appendValue(prettify(list));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String prettify(List<String> items) {
|
|
|
|
|
List<String> pretty = new ArrayList<String>();
|
|
|
|
|
for (String item : items) {
|
|
|
|
|
if (item.contains("$AutoConfigure")) {
|
|
|
|
|
item = item.substring(item.indexOf("$AutoConfigure")
|
|
|
|
|
+ "$AutoConfigure".length());
|
|
|
|
|
}
|
|
|
|
|
pretty.add(item);
|
|
|
|
|
}
|
|
|
|
|
return pretty.toString();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Order(Ordered.LOWEST_PRECEDENCE)
|
|
|
|
|
public static class OrderLowest {
|
|
|
|
|
}
|
|
|
|
@ -94,7 +152,8 @@ public class AutoConfigurationSorterTest {
|
|
|
|
|
public static class AutoConfigureA {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AutoConfigureAfter({ AutoConfigureC.class, AutoConfigureD.class })
|
|
|
|
|
@AutoConfigureAfter({ AutoConfigureC.class, AutoConfigureD.class,
|
|
|
|
|
AutoConfigureE.class })
|
|
|
|
|
public static class AutoConfigureB {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -104,4 +163,23 @@ public class AutoConfigurationSorterTest {
|
|
|
|
|
@AutoConfigureAfter(AutoConfigureA.class)
|
|
|
|
|
public static class AutoConfigureD {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class AutoConfigureE {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AutoConfigureBefore(AutoConfigureB.class)
|
|
|
|
|
public static class AutoConfigureW {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class AutoConfigureX {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AutoConfigureBefore(AutoConfigureX.class)
|
|
|
|
|
public static class AutoConfigureY {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AutoConfigureBefore(AutoConfigureY.class)
|
|
|
|
|
public static class AutoConfigureZ {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|