/** * Execute the {@link Callable#call()} method, record the SQL queries * and return the {@link Spy.SpyWithValue} object with stats * @param callable code to test * @param <V> type of return value * @return statistics on executed queries * @throws Exception if underlying code under test throws an Exception * @since 3.1 */ @SuppressWarnings("unchecked") public static <V> Spy.SpyWithValue<V> call(Callable<V> callable) throws Exception { return spy().call(callable); } }
/** * Execute the {@link Callable#call()} method, record the SQL queries * and return the {@link Spy.SpyWithValue} object with stats * @param callable code to test * @param <V> type of return value * @return statistics on executed queries * @throws Exception if underlying code under test throws an Exception * @since 3.1 */ @SuppressWarnings("unchecked") public static <V> Spy.SpyWithValue<V> call(Callable<V> callable) throws Exception { return spy().call(callable); } }
@Test public void testCallThrowsException() throws Exception { try { Sniffer.expect(1).call(() -> { throw new RuntimeException(); }); } catch (RuntimeException e) { assertNotNull(e); assertNull(e.getCause()); assertEquals(1, e.getSuppressed().length); assertTrue(WrongNumberOfQueriesError.class.isAssignableFrom(e.getSuppressed()[0].getClass())); } }