title: Pass a test result to ITestResult in Selenium using Java
body: <p>I need to pass a result value to the <code>check</code> method that I have.</p>
  
  <pre><code>@Test
      public void test1()
      {
          test = extent.createTest("Test Case 4 : Checking displayed date against current date",
                  "Checking if the date displayed on the check in and check out box is equal to the current date");
  
          String checkin = driver.findElement(By.id("from")).getAttribute("value");
          test.info(checkin);
  
          String timeStamp = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
  
          if (checkin.equals(timeStamp))
          {
              test.info("The checkin in date " + checkin + " is equal to the current date " + timeStamp);
          } else
          {
              test.info("The checkin in date " + checkin + " does not equal the current date " + timeStamp);
          }
  
      }
  
      @AfterMethod
      public void check(ITestResult result) throws IOException
      {
          if (result.getStatus() == ITestResult.FAILURE)
          {
              String screenshotPath = GetScreenshot.capture(driver);
              test.fail("Test Case Failed");
              test.info(result.getThrowable());
              test.info("Screenshot Below : " + test.addScreenCaptureFromPath(screenshotPath));
  
          } else if (result.getStatus() == ITestResult.SKIP)
          {
              test.skip("Test Case Has Been Skipped");
          } else
          {
              test.pass("Test Case Passed");
          }
      }
  </code></pre>
  
  <p>So what I want to accomplish is if the <code>checkin</code> is equal to the <code>timeStamp</code> then the test should pass and if <code>checkin</code> is not equal to the <code>timeStamp</code> the test should fail. For my current code, the tests pass in both the situations.</p>
  
  <p>Is there anyway that I could pass a <code>test.fail()</code> or something to the <code>check</code> method.</p>
  
  <p>I tried <code>check(ITestResult.FAILURE);</code> which didn't work.</p>
  
  <p>I also tried <code>check((ITestResult) test.fail("Test has Failed"));</code> which threw a <code>ClassCastException</code>.</p>