类com.google.common.reflect.ClassPath.ResourceInfo源码实例Demo

下面列出了怎么用com.google.common.reflect.ClassPath.ResourceInfo的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: nomulus   文件: GenrulePremiumListTest.java
@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);
}
 
源代码2 项目: nomulus   文件: GenruleReservedListTest.java
@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);
}
 
@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;
}