public static List<SqlExpectation> buildSqlExpectationList(Method method) { SqlExpectations sqlExpectations = method.getAnnotation(SqlExpectations.class); SqlExpectation sqlExpectation = method.getAnnotation(SqlExpectation.class); NoSql noSql = method.getAnnotation(NoSql.class); if (null == sqlExpectations) sqlExpectations = Expectations.SqlExpectationsAdapter.adapter( method.getAnnotation(Expectations.class) ); if (null == sqlExpectation) sqlExpectation = Expectation.SqlExpectationAdapter.adapter( method.getAnnotation(Expectation.class) ); if (null == noSql && null != method.getAnnotation(NoQueriesAllowed.class)) noSql = method.getAnnotation(NoQueriesAllowed.class).annotationType().getAnnotation(NoSql.class); return buildSqlExpectationList(method.getDeclaringClass(), sqlExpectations, sqlExpectation, noSql); }
public static List<SqlExpectation> buildSqlExpectationList(Class<?> declaringClass, SqlExpectations sqlExpectations, SqlExpectation sqlExpectation, NoSql noSql) { // If no annotations present, check the test class and its superclasses for (Class<?> testClass = declaringClass; null == sqlExpectations && null == sqlExpectation && null == noSql && !Object.class.equals(testClass); testClass = testClass.getSuperclass()) { sqlExpectations = testClass.getAnnotation(SqlExpectations.class); sqlExpectation = testClass.getAnnotation(SqlExpectation.class); noSql = testClass.getAnnotation(NoSql.class); if (null == sqlExpectations) sqlExpectations = Expectations.SqlExpectationsAdapter.adapter( testClass.getAnnotation(Expectations.class) ); if (null == sqlExpectation) sqlExpectation = Expectation.SqlExpectationAdapter.adapter( testClass.getAnnotation(Expectation.class) ); if (null == noSql && null != testClass.getAnnotation(NoQueriesAllowed.class)) noSql = testClass.getAnnotation(NoQueriesAllowed.class).annotationType().getAnnotation(NoSql.class); } return AnnotationProcessor.buildSqlExpectationList(sqlExpectations, sqlExpectation, noSql); }
@Test(expected = IllegalArgumentException.class) @Expectation(threads = Threads.ANY, query = Query.MERGE, atLeast = 2, atMost = 5, value = 3) public void testIncorrectExpectationAnnotation() throws NoSuchMethodException { AnnotationProcessor.buildSqlExpectationList( AnnotationProcessorTest.class.getMethod("testIncorrectExpectationAnnotation") ); }
@Test(expected = IllegalArgumentException.class) @Expectations( @Expectation(threads = Threads.ANY, query = Query.MERGE, atLeast = 2, atMost = 5, value = 3) ) public void testIncorrectExpectationsAnnotation() throws NoSuchMethodException { AnnotationProcessor.buildSqlExpectationList( AnnotationProcessorTest.class.getMethod("testIncorrectExpectationsAnnotation") ); }
private static List<SqlExpectation> buildSqlExpectationList(Description description) { SqlExpectations sqlExpectations = description.getAnnotation(SqlExpectations.class); SqlExpectation sqlExpectation = description.getAnnotation(SqlExpectation.class); NoSql noSql = description.getAnnotation(NoSql.class); if (null == sqlExpectations) sqlExpectations = Expectations.SqlExpectationsAdapter.adapter( description.getAnnotation(Expectations.class) ); if (null == sqlExpectation) sqlExpectation = Expectation.SqlExpectationAdapter.adapter( description.getAnnotation(Expectation.class) ); if (null == noSql && null != description.getAnnotation(NoQueriesAllowed.class)) noSql = description.getAnnotation(NoQueriesAllowed.class).annotationType().getAnnotation(NoSql.class); return AnnotationProcessor.buildSqlExpectationList(description.getTestClass(), sqlExpectations, sqlExpectation, noSql); }
sqlExpectationList = AnnotationProcessor.buildSqlExpectationList(method); } catch (IllegalArgumentException e) { fail(testResult, e.getMessage());
List<SqlExpectation> sqlExpectationList = AnnotationProcessor.buildSqlExpectationList(testMethod);
@Test @Expectation(threads = Threads.OTHERS, query = Query.INSERT, atLeast = 2, atMost = 5) public void testCorrectExpectationAnnotation() throws NoSuchMethodException { List<SqlExpectation> sqlExpectations = AnnotationProcessor.buildSqlExpectationList( AnnotationProcessorTest.class.getMethod("testCorrectExpectationAnnotation") ); assertNotNull(sqlExpectations); assertEquals(1, sqlExpectations.size()); SqlExpectation sqlExpectation = sqlExpectations.get(0); assertEquals(SqlStatement.INSERT, sqlExpectation.query()); assertEquals(Threads.OTHERS, sqlExpectation.threads()); assertEquals(2, sqlExpectation.count().min()); assertEquals(5, sqlExpectation.count().max()); assertEquals(-1, sqlExpectation.count().value()); assertEquals(-1, sqlExpectation.rows().value()); assertEquals(-1, sqlExpectation.rows().value()); assertEquals(-1, sqlExpectation.rows().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()); }
}) public void testCorrectExpectationsAnnotation() throws NoSuchMethodException { List<SqlExpectation> sqlExpectations = AnnotationProcessor.buildSqlExpectationList( AnnotationProcessorTest.class.getMethod("testCorrectExpectationsAnnotation") );