@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 testRecordQueriesOtherThreadsPositive() throws Exception { Sniffer.execute(() -> { executeStatement(); Thread thread = new Thread(BaseTest::executeStatement); thread.start(); thread.join(); }).verifyAtMostOnce(Threads.OTHERS); }
@Test public void testRecordQueriesOtherThreadsNegative() throws Exception { try { Sniffer.execute(() -> { executeStatement(); Thread thread = new Thread(BaseTest::executeStatement); thread.start(); thread.join(); }).verifyNever(Threads.OTHERS); fail(); } catch (WrongNumberOfQueriesError e) { assertNotNull(e); } }
@Test public void testSpyClosed() throws Exception { Spy spy = Sniffer.execute(() -> { executeStatement(); Thread thread = new Thread(BaseTest::executeStatement); thread.start(); thread.join(); }).expectAtMostOnce(Threads.OTHERS); spy.close(); try { spy.verify(1); } catch (Spy.SpyClosedException e) { assertNotNull(e); assertNotNull(e.getCloseStackTrace()); assertNotNull(e.getCloseStackTrace()[1]); StackTraceElement stackTraceElement = e.getCloseStackTrace()[1]; assertEquals("io.sniffy.SnifferTest", stackTraceElement.getClassName()); assertEquals("testSpyClosed", stackTraceElement.getMethodName()); } }