public static void assertAllTestsPresentByMetadata( @NotNull Class<?> testCaseClass, @NotNull File testDataDir, @NotNull Pattern filenamePattern, boolean recursive, @NotNull String... excludeDirs) { TestMetadata testClassMetadata = testCaseClass.getAnnotation(TestMetadata.class); Assert.assertNotNull("No metadata for class: " + testCaseClass, testClassMetadata); String rootPath = testClassMetadata.value(); File rootFile = new File(rootPath); Set<String> filePaths = collectPathsMetadata(testCaseClass); Set<String> exclude = SetsKt.setOf(excludeDirs); File[] files = testDataDir.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { if (recursive && containsTestData(file, filenamePattern) && !exclude.contains(file.getName())) { assertTestClassPresentByMetadata(testCaseClass, file); } } else if (filenamePattern.matcher(file.getName()).matches()) { assertFilePathPresent(file, rootFile, filePaths); } } } }
/** * Register an ability by its class object * * @param cls the ability class */ private static void register(Class<? extends Ability> cls, boolean announce) { AbilityInfo info = cls.getAnnotation(AbilityInfo.class); if (info == null) return; // Map all the aliases for (String alias : info.aliases()) { abilities.put(alias, cls); } // Announce custom abilities if (announce) Messenger.info("Loaded custom ability '" + info.name() + "'"); }
private static void assertTestClassPresentByMetadata( @NotNull Class<?> outerClass, @NotNull File testDataDir) { for (Class<?> nestedClass : outerClass.getDeclaredClasses()) { TestMetadata testMetadata = nestedClass.getAnnotation(TestMetadata.class); if (testMetadata != null && testMetadata.value().equals(getFilePath(testDataDir))) { return; } } Assert.fail( "Test data directory missing from the generated test class: " + testDataDir + "\n" + PLEASE_REGENERATE_TESTS); }
public static void assertAllTestsPresentInSingleGeneratedClass( @NotNull Class<?> testCaseClass, @NotNull File testDataDir, @NotNull final Pattern filenamePattern) { TestMetadata testClassMetadata = testCaseClass.getAnnotation(TestMetadata.class); Assert.assertNotNull("No metadata for class: " + testCaseClass, testClassMetadata); final File rootFile = new File(testClassMetadata.value()); final Set<String> filePaths = collectPathsMetadata(testCaseClass); FileUtil.processFilesRecursively( testDataDir, new Processor<File>() { @Override public boolean process(File file) { if (file.isFile() && filenamePattern.matcher(file.getName()).matches()) { assertFilePathPresent(file, rootFile, filePaths); } return true; } }); }