Beispiel #1
0
  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);
        }
      }
    }
  }
Beispiel #2
0
 private static Set<String> collectMethodsMetadata(Class<?> testCaseClass) {
   Set<String> filePaths = Sets.newHashSet();
   for (Method method : testCaseClass.getDeclaredMethods()) {
     TestMetadata testMetadata = method.getAnnotation(TestMetadata.class);
     if (testMetadata != null) {
       filePaths.add(testMetadata.value());
     }
   }
   return filePaths;
 }
Beispiel #3
0
 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);
 }
Beispiel #4
0
  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;
          }
        });
  }