private static void ensureSpringRulesAreNotPresent(Class<?> testClass) { for (Field field : testClass.getFields()) { if (SpringClassRule.class.isAssignableFrom(field.getType())) { throw new IllegalStateException(String.format("Detected SpringClassRule field in test class [%s], " + "but SpringClassRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName())); } if (SpringMethodRule.class.isAssignableFrom(field.getType())) { throw new IllegalStateException(String.format("Detected SpringMethodRule field in test class [%s], " + "but SpringMethodRule cannot be used with the SpringJUnit4ClassRunner.", testClass.getName())); } } }