@SuppressWarnings("all") public Class<? extends Throwable> expectedException(Method method) { Test annotation = method.getAnnotation(Test.class); if (annotation == null || annotation.expected() == None.class) return null; else return annotation.expected(); }
private Class<? extends Throwable> getExpectedException(Test annotation) { if (annotation == null || annotation.expected() == None.class) { return null; } else { return annotation.expected(); } }
protected Class<? extends Throwable> getExpectedException() { Test annotation = fMethod.getAnnotation(Test.class); if (annotation == null || annotation.expected() == None.class) { return null; } else { return annotation.expected(); } }
@Override protected void runTest() throws Throwable { try { long start = System.currentTimeMillis(); method.invoke(testObject, (Object[])null); if (expectedException != None.class) { throw new AssertionFailedError( "No error was generated for a test case which specifies an error."); } if (timeout > 0){ long elapsed = System.currentTimeMillis() - start; if (elapsed > timeout) { throw new AssertionFailedError("Test took longer than the specified timeout."); } } } catch (InvocationTargetException e) { Throwable thrown = e.getCause(); if (thrown == null) { // probably should not happen throw e; } if (expectedException == None.class){ // Convert JUnit4 AssertionError failures to JUnit3 style so // will be treated as failure rather than error. if (thrown instanceof AssertionError && !(thrown instanceof AssertionFailedError)){ AssertionFailedError afe = new AssertionFailedError(thrown.toString()); // copy the original stack trace afe.setStackTrace(thrown.getStackTrace()); throw afe; } throw thrown; } if (!expectedException.isAssignableFrom(thrown.getClass())){ throw new AssertionFailedError("The wrong exception was thrown from the test case"); } } }
@Test(expected = None.class) public void testConstructorNameRequires() { assertNotNull(Argument.create("thisName", Requires.FALSE)); assertNotNull(Argument.create("a", Requires.OPTIONAL)); assertNotNull(Argument.create("JustANormalLongExtendedNoSpacedArgument", Requires.TRUE)); }
@Test(expected = None.class) public void testConstructorNameRequiresDescription() { assertNotNull(Argument.create("name", Requires.FALSE, "Desc")); }
@Test(expected = None.class) public void testConstructorNameRequiresValidValuesDefaultValue() { assertNotNull(Argument.create("Name", Requires.OPTIONAL, new String[]{"default"}, "default")); }
@Test(expected = None.class) public void testConstructorNameRequiresDescriptionValidValuesDefaultValue() { assertNotNull(Argument.create("Name", Requires.FALSE, "Desc", new String[]{"Valid", "Values"}, "Values")); }
@Test(expected = None.class) public void shouldBeStacked() { tracer.start(); tracer.get("X-Trace-ID"); tracer.start(); }
@Theory @Test(expected = None.class) public void equalsThrowsNoException(Object a, Object b) { assumeNotNull(a); a.equals(b); }