Skip to content
This repository was archived by the owner on Nov 3, 2022. It is now read-only.

Commit 8a32ff8

Browse files
committed
Add test to check behaviour if no modules are detected.
1 parent d0abe2c commit 8a32ff8

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies {
2626
compile "ninja.leaping.configurate:configurate-core:3.1"
2727

2828
testCompile "junit:junit:4.12"
29-
testCompile "org.mockito:mockito-all:1.10.19"
29+
testCompile "org.mockito:mockito-core:1.10.19"
3030
testCompile "org.powermock:powermock-module-junit4:1.6.4"
3131
testCompile "org.powermock:powermock-api-mockito:1.6.4"
3232
}

src/main/java/uk/co/drnaylor/quickstart/ModuleContainer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ public static ModuleContainer.Builder builder() {
104104
private <N extends ConfigurationNode> ModuleContainer(ConfigurationLoader<N> configurationLoader, ClassLoader loader, String packageBase, ModuleConstructor constructor) throws QuickStartModuleDiscoveryException {
105105

106106
try {
107-
Preconditions.checkNotNull(configurationLoader);
108-
Preconditions.checkNotNull(loader);
109-
Preconditions.checkNotNull(packageBase);
110-
Preconditions.checkNotNull(constructor);
111-
112107
this.config = new SystemConfig<>(configurationLoader);
113108
this.constructor = constructor;
114109
this.classLoader = loader;
@@ -123,7 +118,7 @@ private <N extends ConfigurationNode> ModuleContainer(ConfigurationLoader<N> con
123118
/**
124119
* Starts discovery of modules.
125120
*/
126-
private void discoverModules() throws IOException {
121+
private void discoverModules() throws IOException, QuickStartModuleDiscoveryException {
127122
Preconditions.checkState(currentPhase == ConstructionPhase.INITALISED);
128123
currentPhase = ConstructionPhase.DISCOVERING;
129124

@@ -133,6 +128,10 @@ private void discoverModules() throws IOException {
133128
.filter(Module.class::isAssignableFrom)
134129
.map(x -> (Class<? extends Module>)x.asSubclass(Module.class)).collect(Collectors.toSet());
135130

131+
if (modules.isEmpty()) {
132+
throw new QuickStartModuleDiscoveryException("No modules were found", null);
133+
}
134+
136135
// Put the modules into the discoverer.
137136
modules.forEach(modulePopulator);
138137

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* This file is part of QuickStart Module Loader, licensed under the MIT License (MIT). See the LICENSE.txt file
3+
* at the root of this project for more details.
4+
*/
5+
package uk.co.drnaylor.quickstart.tests.modules.exceptions.notamodule;
6+
7+
public class NotAModule {
8+
}

src/test/java/uk/co/drnaylor/quickstart/tests/tests/ModuleContainerConstructionTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*/
55
package uk.co.drnaylor.quickstart.tests.tests;
66

7+
import org.junit.Rule;
78
import org.junit.Test;
9+
import org.junit.rules.ExpectedException;
810
import uk.co.drnaylor.quickstart.ModuleContainer;
911
import uk.co.drnaylor.quickstart.config.ModulesConfigAdapter;
1012
import uk.co.drnaylor.quickstart.config.SimpleNodeConfigAdapter;
@@ -17,6 +19,17 @@
1719

1820
public class ModuleContainerConstructionTests extends FakeLoaderTests {
1921

22+
@Rule
23+
public ExpectedException expectedException = ExpectedException.none();
24+
25+
@Test
26+
public void testThatNoModulesThrow() throws Exception {
27+
expectedException.expect(QuickStartModuleDiscoveryException.class);
28+
expectedException.expectMessage("Unable to start QuickStart");
29+
30+
getContainer("uk.co.drnaylor.quickstart.tests.modules.exceptions.notamodule");
31+
}
32+
2033
@Test(expected = QuickStartModuleLoaderException.Construction.class)
2134
public void testThatUnconstructableModulesThrow() throws QuickStartModuleDiscoveryException, QuickStartModuleLoaderException.Enabling, QuickStartModuleLoaderException.Construction {
2235
getContainer("uk.co.drnaylor.quickstart.tests.modules.exceptions.construction").loadModules(true);

0 commit comments

Comments
 (0)