geforkt von Mirrors/Velocity
Use more obvious/broken-down test cases for topological sort tests
Dieser Commit ist enthalten in:
Ursprung
a5350c6822
Commit
3b6f8e2421
@ -14,49 +14,64 @@ import org.junit.jupiter.api.Test;
|
|||||||
|
|
||||||
class PluginDependencyUtilsTest {
|
class PluginDependencyUtilsTest {
|
||||||
|
|
||||||
private static final PluginDescription NO_DEPENDENCY_1_EXAMPLE = testDescription("example");
|
private static final PluginDescription NO_DEPENDENCY = testDescription("trivial");
|
||||||
private static final PluginDescription NEVER_DEPENDED = testDescription("and-again");
|
private static final PluginDescription NO_DEPENDENCY_2 = testDescription("trivial2");
|
||||||
private static final PluginDescription SOFT_DEPENDENCY_EXISTS = testDescription("soft",
|
private static final PluginDescription HAS_DEPENDENCY_1 = testDescription("dependent1",
|
||||||
ImmutableList.of(new PluginDependency("example", "", true)));
|
new PluginDependency("trivial", null, false));
|
||||||
private static final PluginDescription SOFT_DEPENDENCY_DOES_NOT_EXIST = testDescription("fluffy",
|
private static final PluginDescription HAS_DEPENDENCY_2 = testDescription("dependent2",
|
||||||
ImmutableList.of(new PluginDependency("i-dont-exist", "", false)));
|
new PluginDependency("dependent1", null, false));
|
||||||
private static final PluginDescription MULTI_DEPENDENCY = testDescription("multi-depend",
|
private static final PluginDescription HAS_DEPENDENCY_3 = testDescription("dependent3",
|
||||||
ImmutableList.of(
|
new PluginDependency("trivial", null, false));
|
||||||
new PluginDependency("example", "", false)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
private static final PluginDescription TEST_WITH_DUPLICATE_DEPEND = testDescription("dup-depend",
|
|
||||||
ImmutableList.of(
|
|
||||||
new PluginDependency("multi-depend", "", false)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
private static final PluginDescription CIRCULAR_DEPENDENCY_1 = testDescription("circle",
|
private static final PluginDescription CIRCULAR_DEPENDENCY_1 = testDescription("circle",
|
||||||
ImmutableList.of(new PluginDependency("oval", "", false)));
|
new PluginDependency("oval", "", false));
|
||||||
private static final PluginDescription CIRCULAR_DEPENDENCY_2 = testDescription("oval",
|
private static final PluginDescription CIRCULAR_DEPENDENCY_2 = testDescription("oval",
|
||||||
ImmutableList.of(new PluginDependency("circle", "", false)));
|
new PluginDependency("circle", "", false));
|
||||||
|
|
||||||
private static final ImmutableList<PluginDescription> EXPECTED = ImmutableList.of(
|
|
||||||
NEVER_DEPENDED,
|
|
||||||
NO_DEPENDENCY_1_EXAMPLE,
|
|
||||||
MULTI_DEPENDENCY,
|
|
||||||
TEST_WITH_DUPLICATE_DEPEND,
|
|
||||||
SOFT_DEPENDENCY_DOES_NOT_EXIST,
|
|
||||||
SOFT_DEPENDENCY_EXISTS
|
|
||||||
);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void sortCandidates() throws Exception {
|
void sortCandidatesTrivial() throws Exception {
|
||||||
List<PluginDescription> descriptionList = new ArrayList<>();
|
List<PluginDescription> descriptionList = new ArrayList<>();
|
||||||
descriptionList.add(NO_DEPENDENCY_1_EXAMPLE);
|
assertEquals(descriptionList, PluginDependencyUtils.sortCandidates(descriptionList));
|
||||||
descriptionList.add(NEVER_DEPENDED);
|
}
|
||||||
descriptionList.add(SOFT_DEPENDENCY_DOES_NOT_EXIST);
|
|
||||||
descriptionList.add(SOFT_DEPENDENCY_EXISTS);
|
|
||||||
descriptionList.add(MULTI_DEPENDENCY);
|
|
||||||
descriptionList.add(TEST_WITH_DUPLICATE_DEPEND);
|
|
||||||
descriptionList.sort(Comparator.comparing(PluginDescription::getId));
|
|
||||||
|
|
||||||
assertEquals(EXPECTED, PluginDependencyUtils.sortCandidates(descriptionList));
|
@Test
|
||||||
|
void sortCandidatesSingleton() throws Exception {
|
||||||
|
List<PluginDescription> plugins = ImmutableList.of(NO_DEPENDENCY);
|
||||||
|
assertEquals(plugins, PluginDependencyUtils.sortCandidates(plugins));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sortCandidatesBasicDependency() throws Exception {
|
||||||
|
List<PluginDescription> plugins = ImmutableList.of(HAS_DEPENDENCY_1, NO_DEPENDENCY);
|
||||||
|
List<PluginDescription> expected = ImmutableList.of(NO_DEPENDENCY, HAS_DEPENDENCY_1);
|
||||||
|
assertEquals(expected, PluginDependencyUtils.sortCandidates(plugins));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sortCandidatesNestedDependency() throws Exception {
|
||||||
|
List<PluginDescription> plugins = ImmutableList.of(HAS_DEPENDENCY_1, HAS_DEPENDENCY_2,
|
||||||
|
NO_DEPENDENCY);
|
||||||
|
List<PluginDescription> expected = ImmutableList.of(NO_DEPENDENCY, HAS_DEPENDENCY_1,
|
||||||
|
HAS_DEPENDENCY_2);
|
||||||
|
assertEquals(expected, PluginDependencyUtils.sortCandidates(plugins));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sortCandidatesTypical() throws Exception {
|
||||||
|
List<PluginDescription> plugins = ImmutableList.of(HAS_DEPENDENCY_2, NO_DEPENDENCY_2,
|
||||||
|
HAS_DEPENDENCY_1, NO_DEPENDENCY);
|
||||||
|
List<PluginDescription> expected = ImmutableList.of(NO_DEPENDENCY, HAS_DEPENDENCY_1,
|
||||||
|
HAS_DEPENDENCY_2, NO_DEPENDENCY_2);
|
||||||
|
assertEquals(expected, PluginDependencyUtils.sortCandidates(plugins));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sortCandidatesMultiplePluginsDependentOnOne() throws Exception {
|
||||||
|
List<PluginDescription> plugins = ImmutableList.of(HAS_DEPENDENCY_3, HAS_DEPENDENCY_1,
|
||||||
|
NO_DEPENDENCY);
|
||||||
|
List<PluginDescription> expected = ImmutableList.of(NO_DEPENDENCY, HAS_DEPENDENCY_3,
|
||||||
|
HAS_DEPENDENCY_1);
|
||||||
|
assertEquals(expected, PluginDependencyUtils.sortCandidates(plugins));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -65,14 +80,10 @@ class PluginDependencyUtilsTest {
|
|||||||
assertThrows(IllegalStateException.class, () -> PluginDependencyUtils.sortCandidates(descs));
|
assertThrows(IllegalStateException.class, () -> PluginDependencyUtils.sortCandidates(descs));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PluginDescription testDescription(String id) {
|
private static PluginDescription testDescription(String id, PluginDependency... dependencies) {
|
||||||
return testDescription(id, ImmutableList.of());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PluginDescription testDescription(String id, List<PluginDependency> dependencies) {
|
|
||||||
return new VelocityPluginDescription(
|
return new VelocityPluginDescription(
|
||||||
id, "tuxed", "0.1", null, null, ImmutableList.of(),
|
id, "tuxed", "0.1", null, null, ImmutableList.of(),
|
||||||
dependencies, null
|
ImmutableList.copyOf(dependencies), null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren