@After public void tearDown(){ PrivateAccess.setShouldNotFailTest(true); }
@Before public void init(){ PrivateAccess.setShouldNotFailTest(false); }
@Test public void testSetField_fail_on_error(){ PrivateAccess.setShouldNotFailTest(false); try { PrivateAccess.setVariable(FooFields.class, null, "a non-existing field", 42); Assert.fail(); } catch (FalsePositiveException e){ Assert.fail(); } catch (RuntimeException e){ //Ok, expected } finally { PrivateAccess.setShouldNotFailTest(true); } }
@Test public void testMethod_fail_on_error(){ PrivateAccess.setShouldNotFailTest(false); try { PrivateAccess.callMethod(FooMethods.class, null, "a non-existing method", new Object[0], new Class<?>[0]); Assert.fail(); } catch (FalsePositiveException e){ Assert.fail(); } catch (Throwable e){ //Ok, expected } finally { PrivateAccess.setShouldNotFailTest(true); } }
@Test public void testSetField_error(){ PrivateAccess.setShouldNotFailTest(true); PrivateAccess.setVariable(FooFields.class, null, "a non-existing field", 42); Assert.fail(); // this should never be reached, as failed "Assumption" inside setVariable }
@Test public void testMethod_error() throws Throwable { PrivateAccess.setShouldNotFailTest(true); PrivateAccess.callMethod(FooMethods.class, null,"a non-existing method", new Object[0], new Class<?>[0]); Assert.fail(); }