LoginSystem/src/test/java/fr/xephi/authme/CodeClimateConfigTest.java
ljacqu cb73160bcd Minor - simplify CodeClimateConfigTest
- No need to load the class when we just want to ensure that the file exists
2017-07-08 23:10:42 +02:00

49 lines
1.6 KiB
Java

package fr.xephi.authme;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.junit.Test;
import java.io.File;
import java.util.List;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
/**
* Consistency test for the CodeClimate configuration file.
*/
public class CodeClimateConfigTest {
private static final String CONFIG_FILE = ".codeclimate.yml";
@Test
public void shouldHaveExistingClassesInExclusions() {
// given / when
FileConfiguration configuration = YamlConfiguration.loadConfiguration(new File(CONFIG_FILE));
List<String> excludePaths = configuration.getStringList("exclude_paths");
// then
assertThat(excludePaths, not(empty()));
for (String path : excludePaths) {
verifySourceFileExists(path);
}
}
private static void verifySourceFileExists(String path) {
// 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.
if (!path.startsWith(TestHelper.SOURCES_FOLDER)) {
fail("Unexpected path '" + path + "': expected to start with sources folder");
} else if (!path.endsWith(".java")) {
fail("Expected path '" + path + "' to end with '.java'");
}
if (new File("/" + path).exists()) {
fail("Path '" + path + "' does not exist!");
}
}
}