@Test
 public void testSetHeaderTwice() {
   final HeaderCheck check = new HeaderCheck();
   check.setHeader("Header");
   try {
     check.setHeader("Header2");
     fail("ConversionException is expected");
   } catch (ConversionException ex) {
     assertEquals(
         "header has already been set - " + "set either header or headerFile, not both",
         ex.getMessage());
   }
 }
  @Test
  public void testIoExceptionWhenLoadingHeader() throws Exception {
    final HeaderCheck check = PowerMockito.spy(new HeaderCheck());
    PowerMockito.doThrow(new IOException("expected exception"))
        .when(check, "loadHeader", anyObject());

    try {
      check.setHeader("header");
      fail("Exception expected");
    } catch (ConversionException ex) {
      assertTrue(ex.getCause() instanceof IOException);
      assertEquals("unable to load header", ex.getMessage());
    }
  }
  @Test
  public void testIoExceptionWhenLoadingHeaderFile() throws Exception {
    final HeaderCheck check = PowerMockito.spy(new HeaderCheck());
    PowerMockito.doThrow(new IOException("expected exception"))
        .when(check, "loadHeader", anyObject());

    check.setHeaderFile(getPath("InputRegexpHeader1.java"));

    final Method loadHeaderFile = AbstractHeaderCheck.class.getDeclaredMethod("loadHeaderFile");
    loadHeaderFile.setAccessible(true);
    try {
      loadHeaderFile.invoke(check);
      fail("Exception expected");
    } catch (InvocationTargetException ex) {
      assertTrue(ex.getCause() instanceof CheckstyleException);
      assertEquals(
          "unable to load header file " + getPath("InputRegexpHeader1.java"),
          ex.getCause().getMessage());
    }
  }