/** * @return a new {@link Spy} instance with an expectation initialized * @see #spy() * @see Spy#expectAtMostOnce(Threads) * @since 2.0 */ @Deprecated public static Spy expectAtMostOnce(Threads threadMatcher) { return spy().expectAtMostOnce(threadMatcher); }
@Test public void testTryWithResourceApi_ExactCurrentThread() throws Exception { try (Spy ignored = Sniffer.expect(2, Threads.CURRENT)) { executeStatements(2); } }
@Test public void testAtMostMergePositive() throws Exception { try (Spy ignored = Sniffer.expectAtMost(2, MERGE)) { executeStatement(MERGE); } try (Spy ignored = Sniffer.expectAtMost(2, MERGE)) { executeStatement(DELETE); executeStatements(2, MERGE); } }
@Test public void testNeverInsertPositive() throws Exception { try (Spy ignored = Sniffer.expectNever(INSERT)) { executeStatement(SELECT); } }
@Test public void testAtLeastDeleteOtherThreadPositive() throws Exception { try (Spy ignored = Sniffer.expectAtLeast(2, Threads.OTHERS, DELETE)) { executeStatementsInOtherThread(2, DELETE); } }
@Test(expected = WrongNumberOfQueriesError.class) public void testAtMostOnceUpdateNegative() throws Exception { try (Spy ignored = Sniffer.expectAtMostOnce(UPDATE)) { executeStatements(2, UPDATE); } }
@Test public void testTryWithResourceApi_Between() throws Exception { try (Spy ignored = Sniffer.expectBetween(2, 10)) { executeStatements(7); } }
@Test public void testRecordQueriesThreadLocalPositive() throws Exception { Sniffer.execute(() -> { executeStatement(); Thread thread = new Thread(BaseTest::executeStatement); thread.start(); thread.join(); }).verifyAtMostOnce(Threads.CURRENT); }
@Test public void testExecutedStatements() throws Exception { int actual = Sniffer.executedStatements(); executeStatement(); executeStatementInOtherThread(); assertEquals(2, Sniffer.executedStatements() - actual); }
@Test public void testRecordQueriesWithValue() throws Exception { assertEquals("test", Sniffer.call(() -> { executeStatement(); return "test"; }).verifyAtMostOnce().getValue()); }
@Test public void testTryWithResourceApi_Exact() throws Exception { try (Spy ignored = Sniffer.expect(2)) { executeStatements(2); } }
@Test(expected = WrongNumberOfQueriesError.class) public void testAtMostMergeNegative() throws Exception { try (Spy ignored = Sniffer.expectAtMost(2, MERGE)) { executeStatements(3, MERGE); } }
@Test(expected = WrongNumberOfQueriesError.class) public void testNeverInsertNegative() throws Exception { try (Spy ignored = Sniffer.expectNever(INSERT)) { executeStatement(INSERT); } }
@Test public void testTryWithResourceApi_AtLeast() throws Exception { try (Spy ignored = Sniffer.expectAtLeast(2)) { executeStatements(5); } }
@Test(expected = WrongNumberOfQueriesError.class) public void testAtMostOnceUpdateOtherThreadNegative() throws Exception { try (Spy ignored = Sniffer.expectAtMostOnce(UPDATE, Threads.OTHERS)) { executeStatementsInOtherThread(2, UPDATE); } }
@Test public void testBetweenOtherPositive() throws Exception { try (Spy ignored = Sniffer.expectBetween(2, 4, OTHER)) { executeStatements(3, OTHER); } }
@Test public void testRecordQueriesOtherThreadsPositive() throws Exception { Sniffer.execute(() -> { executeStatement(); Thread thread = new Thread(BaseTest::executeStatement); thread.start(); thread.join(); }).verifyAtMostOnce(Threads.OTHERS); }
/** * @return a new {@link Spy} instance with an expectation initialized * @see #spy() * @see Spy#expectAtLeast(int, Query) * @since 2.2 */ @Deprecated public static Spy expectAtLeast(int allowedStatements, Query query) { return spy().expectAtLeast(allowedStatements, query); }
@Test public void testExactlyOneThreadLocalInsert() throws Exception { try (Spy $= Sniffer.expect(1, Query.INSERT)) { executeStatement(Query.INSERT); } }
@Test(expected = WrongNumberOfQueriesError.class) public void testAtMostMergeOtherThreadNegative() throws Exception { try (Spy ignored = Sniffer.expectAtMost(2, MERGE, Threads.OTHERS)) { executeStatementsInOtherThread(3, MERGE); } }