Java Code Examples for com.google.common.reflect.ClassPath.ResourceInfo

The following examples show how to use com.google.common.reflect.ClassPath.ResourceInfo. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: nomulus   Source File: GenrulePremiumListTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParse_allPremiumLists() throws Exception {
  ClassPath classpath = ClassPath.from(getClass().getClassLoader());
  int numParsed = 0;
  for (ResourceInfo resource : classpath.getResources()) {
    if (resource.getResourceName().startsWith(LISTS_DIRECTORY)
        && resource.getResourceName().endsWith(".txt")) {
      testParseOfPremiumListFile(resource.getResourceName());
      numParsed++;
    }
  }
  assertWithMessage("No premium lists found").that(numParsed).isAtLeast(1);
}
 
Example 2
Source Project: nomulus   Source File: GenruleReservedListTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testParse_allReservedLists() throws Exception {
  ClassPath classpath = ClassPath.from(getClass().getClassLoader());
  int numParsed = 0;
  for (ResourceInfo resource : classpath.getResources()) {
    if (resource.getResourceName().startsWith(LISTS_DIRECTORY)
        && resource.getResourceName().endsWith(".txt")) {
      testParseOfReservedListFile(resource.getResourceName());
      numParsed++;
    }
  }
  assertWithMessage("No reserved lists found").that(numParsed).isAtLeast(1);
}
 
Example 3
@Parameters(name = "{index}: {0}")
public static Iterable<Object[]> data() throws IOException {
  Path testDataPath = Paths.get("com/google/googlejavaformat/java/testdata");
  ClassLoader classLoader = FormatterIntegrationTest.class.getClassLoader();
  Map<String, String> inputs = new TreeMap<>();
  Map<String, String> outputs = new TreeMap<>();
  for (ResourceInfo resourceInfo : ClassPath.from(classLoader).getResources()) {
    String resourceName = resourceInfo.getResourceName();
    Path resourceNamePath = Paths.get(resourceName);
    if (resourceNamePath.startsWith(testDataPath)) {
      Path subPath = testDataPath.relativize(resourceNamePath);
      assertEquals("bad testdata file names", 1, subPath.getNameCount());
      String baseName = getNameWithoutExtension(subPath.getFileName().toString());
      String extension = getFileExtension(subPath.getFileName().toString());
      String contents;
      try (InputStream stream =
          FormatterIntegrationTest.class.getClassLoader().getResourceAsStream(resourceName)) {
        contents = CharStreams.toString(new InputStreamReader(stream, UTF_8));
      }
      switch (extension) {
        case "input":
          inputs.put(baseName, contents);
          break;
        case "output":
          outputs.put(baseName, contents);
          break;
        default:
      }
    }
  }
  List<Object[]> testInputs = new ArrayList<>();
  assertEquals("unmatched inputs and outputs", inputs.size(), outputs.size());
  for (Map.Entry<String, String> entry : inputs.entrySet()) {
    String fileName = entry.getKey();
    String input = inputs.get(fileName);
    assertTrue("unmatched input", outputs.containsKey(fileName));
    String expectedOutput = outputs.get(fileName);
    if (JAVA14_TESTS.contains(fileName) && getMajor() < 14) {
      continue;
    }
    testInputs.add(new Object[] {fileName, input, expectedOutput});
  }
  return testInputs;
}