コード例 #1
0
  @SuppressWarnings("deprecation")
  @Test
  public void testSetters() throws Exception {
    // all  that is set by reflection, so just make code coverage be happy
    final Checker checker = new Checker();
    checker.setClassLoader(getClass().getClassLoader());
    checker.setClassloader(getClass().getClassLoader());
    checker.setBasedir("some");
    checker.setSeverity("ignore");

    PackageObjectFactory factory =
        new PackageObjectFactory(
            new HashSet<String>(), Thread.currentThread().getContextClassLoader());
    checker.setModuleFactory(factory);

    checker.setFileExtensions((String[]) null);
    checker.setFileExtensions(".java", "xml");

    try {
      checker.setCharset("UNKNOWN-CHARSET");
      fail("Exception is expected");
    } catch (UnsupportedEncodingException ex) {
      assertEquals("unsupported charset: 'UNKNOWN-CHARSET'", ex.getMessage());
    }
  }
コード例 #2
0
  @Test
  public void testFileExtensions() throws Exception {
    final Checker checker = new Checker();
    final List<File> files = new ArrayList<>();
    File file = new File("file.pdf");
    files.add(file);
    File otherFile = new File("file.java");
    files.add(otherFile);
    final String[] fileExtensions = {"java", "xml", "properties"};
    checker.setFileExtensions(fileExtensions);
    final int counter = checker.process(files);

    // comparing to 1 as there is only one legal file in input
    assertEquals(1, counter);
  }