public static List<SocketExpectation> buildSocketExpectationList(Method method) { SocketExpectations socketExpectations = method.getAnnotation(SocketExpectations.class); SocketExpectation socketExpectation = method.getAnnotation(SocketExpectation.class); NoSocketsAllowed noSocketsAllowed = method.getAnnotation(NoSocketsAllowed.class); // If no annotations present, check the test class and its superclasses for (Class<?> testClass = method.getDeclaringClass(); null == socketExpectations && null == socketExpectation && null == noSocketsAllowed && !Object.class.equals(testClass); testClass = testClass.getSuperclass()) { socketExpectations = testClass.getAnnotation(SocketExpectations.class); socketExpectation = testClass.getAnnotation(SocketExpectation.class); noSocketsAllowed = testClass.getAnnotation(NoSocketsAllowed.class); } return AnnotationProcessor.buildSocketExpectationList(socketExpectation, socketExpectations, noSocketsAllowed); }
private static List<SocketExpectation> buildSocketExpectationList(Description description) { SocketExpectation socketExpectation = description.getAnnotation(SocketExpectation.class); SocketExpectations socketExpectations = description.getAnnotation(SocketExpectations.class); NoSocketsAllowed noSocketsAllowed = description.getAnnotation(NoSocketsAllowed.class); for (Class<?> testClass = description.getTestClass(); null == socketExpectations && null == socketExpectation && null == noSocketsAllowed && !Object.class.equals(testClass); testClass = testClass.getSuperclass()) { socketExpectations = testClass.getAnnotation(SocketExpectations.class); socketExpectation = testClass.getAnnotation(SocketExpectation.class); noSocketsAllowed = testClass.getAnnotation(NoSocketsAllowed.class); } return AnnotationProcessor.buildSocketExpectationList(socketExpectation, socketExpectations, noSocketsAllowed); }
@Test(expected = IllegalArgumentException.class) @SocketExpectation(threads = Threads.ANY, connections = @Count(min = 2, max = 5, value = 3)) public void testIncorrectSocketExpectationAnnotation() throws NoSuchMethodException { AnnotationProcessor.buildSocketExpectationList( AnnotationProcessorTest.class.getMethod("testIncorrectSocketExpectationAnnotation") ); }
@Test(expected = IllegalArgumentException.class) @SocketExpectations( @SocketExpectation(threads = Threads.ANY, connections = @Count(min = 2, max = 5, value = 3)) ) public void testIncorrectSocketExpectationsAnnotation() throws NoSuchMethodException { AnnotationProcessor.buildSocketExpectationList( AnnotationProcessorTest.class.getMethod("testIncorrectSocketExpectationsAnnotation") ); }
@Test @SocketExpectation(threads = Threads.OTHERS, connections = @Count(min = 2, max = 5)) public void testCorrectSocketExpectationAnnotation() throws NoSuchMethodException { List<SocketExpectation> socketExpectations = AnnotationProcessor.buildSocketExpectationList( AnnotationProcessorTest.class.getMethod("testCorrectSocketExpectationAnnotation") ); assertNotNull(socketExpectations); assertEquals(1, socketExpectations.size()); SocketExpectation socketExpectation = socketExpectations.get(0); assertEquals(Threads.OTHERS, socketExpectation.threads()); assertEquals(2, socketExpectation.connections().min()); assertEquals(5, socketExpectation.connections().max()); assertEquals(-1, socketExpectation.connections().value()); }
socketExpectationList = AnnotationProcessor.buildSocketExpectationList(method); } catch (IllegalArgumentException e) { fail(testResult, e.getMessage());
List<SocketExpectation> socketExpectationList = AnnotationProcessor.buildSocketExpectationList(testMethod); List<SqlExpectation> sqlExpectationList = AnnotationProcessor.buildSqlExpectationList(testMethod);
@Test @SocketExpectations({ @SocketExpectation(threads = Threads.ANY, connections = @Count(min = 2, max = 5)), @SocketExpectation(threads = Threads.CURRENT, connections = @Count(min = 3, max = 6)) }) public void testCorrectSocketExpectationsAnnotation() throws NoSuchMethodException { List<SocketExpectation> socketExpectations = AnnotationProcessor.buildSocketExpectationList( AnnotationProcessorTest.class.getMethod("testCorrectSocketExpectationsAnnotation") ); assertNotNull(socketExpectations); assertEquals(2, socketExpectations.size()); { SocketExpectation socketExpectation = socketExpectations.get(0); assertEquals(Threads.ANY, socketExpectation.threads()); assertEquals(2, socketExpectation.connections().min()); assertEquals(5, socketExpectation.connections().max()); assertEquals(-1, socketExpectation.connections().value()); } { SocketExpectation socketExpectation = socketExpectations.get(1); assertEquals(Threads.CURRENT, socketExpectation.threads()); assertEquals(3, socketExpectation.connections().min()); assertEquals(6, socketExpectation.connections().max()); assertEquals(-1, socketExpectation.connections().value()); } }
@Test public void testNoSqlNoSocketsAllowedInClass() throws NoSuchMethodException { List<SocketExpectation> socketExpectations = AnnotationProcessor.buildSocketExpectationList( AnnotationProcessorTest.class.getMethod("testNoSqlNoSocketsAllowedInClass") ); assertNotNull(socketExpectations); assertEquals(1, socketExpectations.size()); SocketExpectation socketExpectation = socketExpectations.get(0); assertEquals(Threads.CURRENT, socketExpectation.threads()); assertEquals(-1, socketExpectation.connections().min()); assertEquals(-1, socketExpectation.connections().max()); assertEquals(0, socketExpectation.connections().value()); List<SqlExpectation> sqlExpectations = AnnotationProcessor.buildSqlExpectationList( AnnotationProcessorTest.class.getMethod("testNoSqlNoSocketsAllowedInClass") ); assertNotNull(sqlExpectations); assertEquals(1, sqlExpectations.size()); SqlExpectation sqlExpectation = sqlExpectations.get(0); assertEquals(SqlStatement.ANY, sqlExpectation.query()); assertEquals(Threads.CURRENT, sqlExpectation.threads()); assertEquals(-1, sqlExpectation.count().min()); assertEquals(-1, sqlExpectation.count().max()); assertEquals(0, sqlExpectation.count().value()); assertEquals(-1, sqlExpectation.rows().value()); assertEquals(-1, sqlExpectation.rows().value()); assertEquals(-1, sqlExpectation.rows().value()); }