/** * @param expectation * @return * @since 3.1 */ @Override public C verify(Expectation expectation) { checkOpened(); expectation.verify(this); return self(); }
/** * Execute the {@link Executable#execute()} method, record the SQL queries * and return the {@link Spy} object with stats * @param executable code to test * @return statistics on executed queries * @throws RuntimeException if underlying code under test throws an Exception * @since 3.1 */ public static Spy execute(Executable executable) { return spy().execute(executable); }
@Test public void testNeverInsertPositive() throws Exception { Spy spy = Sniffy.spy(); executeStatement(Query.SELECT); spy.verifyNever(Query.INSERT); }
@Test public void testAtMostMergeOtherThreadPositive() throws Exception { Spy spy = Sniffy.spy(); executeStatementInOtherThread(Query.SELECT); executeStatementInOtherThread(Query.MERGE); executeStatements(5, Query.MERGE); spy.verifyAtMost(2, Threads.OTHERS, Query.MERGE); }
@Test public void testNeverInsertOtherThreadPositive() throws Exception { Spy spy = Sniffy.spy(); executeStatementInOtherThread(Query.SELECT); executeStatement(Query.INSERT); spy.verifyNever(Threads.OTHERS, Query.INSERT); }
@Test(expected = WrongNumberOfQueriesError.class) public void testAtLeastDeleteOtherThreadNegative() throws Exception { Spy spy = Sniffy.spy(); executeStatementInOtherThread(Query.DELETE); executeStatement(Query.DELETE); spy.verifyAtLeast(2, Query.DELETE, Threads.OTHERS); }
@Test public void testAtMostOnceUpdatePositive() throws Exception { Spy spy = Sniffy.spy(); executeStatement(Query.UPDATE); spy.verifyAtMostOnce(Query.UPDATE); spy = Sniffy.spy(); executeStatement(Query.DELETE); executeStatement(Query.UPDATE); spy.verifyAtMostOnce(Query.UPDATE); }
@Test public void testBetweenOtherOtherThreadPositive() throws Exception { Spy spy = Sniffy.spy(); executeStatementsInOtherThread(2, Query.OTHER); spy.verifyBetween(2, 4, Threads.OTHERS, Query.OTHER); }
@Test(expected = WrongNumberOfQueriesError.class) public void testAtMostOnceUpdateOtherThreadNegative() throws Exception { Spy spy = Sniffy.spy(); executeStatementsInOtherThread(2, Query.UPDATE); spy.verifyAtMostOnce(Query.UPDATE, Threads.OTHERS); }
@Test(expected = WrongNumberOfQueriesError.class) public void testAtMostMergeOtherThreadNegative() throws Exception { Spy spy = Sniffy.spy(); executeStatementsInOtherThread(3, Query.MERGE); spy.verifyAtMost(2, Query.MERGE, Threads.OTHERS); }
@Test public void testBetweenOtherPositive() throws Exception { Spy spy = Sniffy.spy(); executeStatements(3, Query.OTHER); spy.verifyBetween(2, 4, Query.OTHER); }
@Override public Count count() { return new CountAdapter(expectation.value(), expectation.atLeast(), expectation.atMost()); }
/** * Execute the {@link Executable#execute()} method, record the SQL queries * and return the {@link Spy} object with stats * @param executable code to test * @return statistics on executed queries * @throws RuntimeException if underlying code under test throws an Exception * @since 3.1 */ public static Spy execute(Executable executable) { return spy().execute(executable); }
@Test(expected = WrongNumberOfQueriesError.class) public void testNeverInsertNegative() throws Exception { Spy spy = Sniffy.spy(); executeStatement(Query.INSERT); spy.verifyNever(Query.INSERT); }
/** * @param expectation * @return * @since 3.1 */ @Override public C verify(Expectation expectation) { checkOpened(); expectation.verify(this); return self(); }