/** * @param expectation * @return * @since 3.1 */ @Override public C expect(Expectation expectation) { checkOpened(); expectations.add(expectation); return self(); }
/** * @param expectation * @return * @since 3.1 */ @Override public C expect(Expectation expectation) { checkOpened(); expectations.add(expectation); return self(); }
/** * Verifies all expectations added previously using {@code expect} methods family * @throws SniffyAssertionError if wrong number of queries was executed * @since 2.0 */ @Override public void verify() throws SniffyAssertionError { checkOpened(); SniffyAssertionError assertionError = getSniffyAssertionError(); if (null != assertionError) { throw assertionError; } }
/** * Verifies all expectations added previously using {@code expect} methods family * @throws SniffyAssertionError if wrong number of queries was executed * @since 2.0 */ @Override public void verify() throws SniffyAssertionError { checkOpened(); SniffyAssertionError assertionError = getSniffyAssertionError(); if (null != assertionError) { throw assertionError; } }
/** * @return SniffyAssertionError or null if there are no errors * @since 3.1 */ @Override public SniffyAssertionError getSniffyAssertionError() { checkOpened(); SniffyAssertionError assertionError = null; Throwable currentException = null; for (Expectation expectation : expectations) { try { expectation.verify(this); } catch (SniffyAssertionError e) { if (null == assertionError) { currentException = assertionError = e; } else { currentException.initCause(e); currentException = e; } } } return assertionError; }
/** * Wrapper for {@link Sniffy#spy()} method; useful for chaining * @return a new {@link Spy} instance * @since 2.0 */ public C reset() { checkOpened(); super.reset(); expectations.clear(); return self(); }
/** * @return SniffyAssertionError or null if there are no errors * @since 3.1 */ @Override public SniffyAssertionError getSniffyAssertionError() { checkOpened(); SniffyAssertionError assertionError = null; Throwable currentException = null; for (Expectation expectation : expectations) { try { expectation.verify(this); } catch (SniffyAssertionError e) { if (null == assertionError) { currentException = assertionError = e; } else { currentException.initCause(e); currentException = e; } } } return assertionError; }
/** * Wrapper for {@link Sniffy#spy()} method; useful for chaining * @return a new {@link Spy} instance * @since 2.0 */ public C reset() { checkOpened(); super.reset(); expectations.clear(); return self(); }
/** * @param expectation * @return * @since 3.1 */ @Override public C verify(Expectation expectation) { checkOpened(); expectation.verify(this); return self(); }
/** * @param expectation * @return * @since 3.1 */ @Override public C verify(Expectation expectation) { checkOpened(); expectation.verify(this); return self(); }
/** * Executes the {@link Runnable#run()} method on provided argument and verifies the expectations * @throws SniffyAssertionError if wrong number of queries was executed * @since 2.0 */ public C run(Runnable runnable) throws SniffyAssertionError { checkOpened(); try { runnable.run(); } catch (Throwable e) { throw verifyAndAddToException(e); } verify(); return self(); }
/** * Executes the {@link Runnable#run()} method on provided argument and verifies the expectations * @throws SniffyAssertionError if wrong number of queries was executed * @since 2.0 */ public C run(Runnable runnable) throws SniffyAssertionError { checkOpened(); try { runnable.run(); } catch (Throwable e) { throw verifyAndAddToException(e); } verify(); return self(); }
/** * Executes the {@link Callable#call()} method on provided argument and verifies the expectations * @throws SniffyAssertionError if wrong number of queries was executed * @since 2.0 */ public <V> SpyWithValue<V> call(Callable<V> callable) throws SniffyAssertionError { checkOpened(); V result; try { result = callable.call(); } catch (Throwable e) { throw verifyAndAddToException(e); } verify(); return new SpyWithValue<V>(result); }
/** * Executes the {@link Callable#call()} method on provided argument and verifies the expectations * @throws SniffyAssertionError if wrong number of queries was executed * @since 2.0 */ public <V> SpyWithValue<V> call(Callable<V> callable) throws SniffyAssertionError { checkOpened(); V result; try { result = callable.call(); } catch (Throwable e) { throw verifyAndAddToException(e); } verify(); return new SpyWithValue<V>(result); }
/** * Executes the {@link io.sniffy.Executable#execute()} method on provided argument and verifies the expectations * @throws SniffyAssertionError if wrong number of queries was executed * @since 3.1 */ @Override public C execute(io.sniffy.Executable executable) throws SniffyAssertionError { checkOpened(); try { executable.execute(); } catch (Throwable e) { throw verifyAndAddToException(e); } verify(); return self(); }
/** * Executes the {@link io.sniffy.Executable#execute()} method on provided argument and verifies the expectations * @throws SniffyAssertionError if wrong number of queries was executed * @since 3.1 */ @Override public C execute(io.sniffy.Executable executable) throws SniffyAssertionError { checkOpened(); try { executable.execute(); } catch (Throwable e) { throw verifyAndAddToException(e); } verify(); return self(); }