Minor - simplify CodeClimateConfigTest
- No need to load the class when we just want to ensure that the file exists
This commit is contained in:
parent
919a715ded
commit
cb73160bcd
@ -1,6 +1,5 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import fr.xephi.authme.util.Utils;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -9,9 +8,9 @@ import java.io.File;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.empty;
|
import static org.hamcrest.Matchers.empty;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consistency test for the CodeClimate configuration file.
|
* Consistency test for the CodeClimate configuration file.
|
||||||
@ -22,30 +21,28 @@ public class CodeClimateConfigTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveExistingClassesInExclusions() {
|
public void shouldHaveExistingClassesInExclusions() {
|
||||||
// given
|
// given / when
|
||||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(new File(CONFIG_FILE));
|
FileConfiguration configuration = YamlConfiguration.loadConfiguration(new File(CONFIG_FILE));
|
||||||
List<String> excludePaths = configuration.getStringList("exclude_paths");
|
List<String> excludePaths = configuration.getStringList("exclude_paths");
|
||||||
|
|
||||||
// when / then
|
// then
|
||||||
assertThat(excludePaths, not(empty()));
|
assertThat(excludePaths, not(empty()));
|
||||||
for (String path : excludePaths) {
|
for (String path : excludePaths) {
|
||||||
String className = convertPathToQualifiedClassName(path);
|
verifySourceFileExists(path);
|
||||||
assertThat("No class corresponds to excluded path '" + path + "'",
|
|
||||||
Utils.isClassLoaded(className), equalTo(true));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String convertPathToQualifiedClassName(String path) {
|
private static void verifySourceFileExists(String path) {
|
||||||
// Note ljacqu 20170323: In the future, we could have legitimate exclusions that don't fulfill these checks,
|
// Note ljacqu 20170323: In the future, we could have legitimate exclusions that don't fulfill these checks,
|
||||||
// in which case this test needs to be adapted accordingly.
|
// in which case this test needs to be adapted accordingly.
|
||||||
if (!path.startsWith(TestHelper.SOURCES_FOLDER)) {
|
if (!path.startsWith(TestHelper.SOURCES_FOLDER)) {
|
||||||
throw new IllegalArgumentException("Unexpected path '" + path + "': expected to start with sources folder");
|
fail("Unexpected path '" + path + "': expected to start with sources folder");
|
||||||
} else if (!path.endsWith(".java")) {
|
} else if (!path.endsWith(".java")) {
|
||||||
throw new IllegalArgumentException("Expected path '" + path + "' to end with '.java'");
|
fail("Expected path '" + path + "' to end with '.java'");
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.substring(0, path.length() - ".java".length()) // strip ending .java
|
if (new File("/" + path).exists()) {
|
||||||
.substring(TestHelper.SOURCES_FOLDER.length()) // strip starting src/main/java
|
fail("Path '" + path + "' does not exist!");
|
||||||
.replace('/', '.'); // replace '/' to '.'
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user