private Request applyFilterSpecs(Request request) { try { for (String filterSpec : filterSpecs) { Filter filter = FilterFactories.createFilterFromFilterSpec( request, filterSpec); request = request.filterWith(filter); } return request; } catch (FilterNotCreatedException e) { return errorReport(e); } }
/** * @return the number of tests to be run by the receiver */ public int testCount() { return getDescription().testCount(); } }
@RunWith(SpringRunner.class) public static abstract class BaseTestCase { @Test public void testNothing() { } }
private void configureRunner(Runner runner) throws InvalidOrderingException { Description description = runner.getDescription(); OrderWith orderWith = description.getAnnotation(OrderWith.class); if (orderWith != null) { Ordering ordering = Ordering.definedBy(orderWith.value(), description); ordering.apply(runner); } }
/** * Create a <code>Request</code> that, when processed, will run a single test. * This is done by filtering out all other tests. This method is used to support rerunning * single tests. * * @param clazz the class of the test * @param methodName the name of the test * @return a <code>Request</code> that will cause a single test be run */ public static Request method(Class<?> clazz, String methodName) { Description method = Description.createTestDescription(clazz, methodName); return Request.aClass(clazz).filterWith(method); }
/** * Run all the tests in <code>classes</code>. * * @param classes the classes containing tests * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Class<?>... classes) { return run(Request.classes(defaultComputer(), classes)); }
/** * Run all the tests in <code>classes</code>. * * @param computer Helps construct Runners from classes * @param classes the classes containing tests * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Computer computer, Class<?>... classes) { return run(Request.classes(computer, classes)); }
/** * Create a <code>Request</code> that, when processed, will run all the tests * in a set of classes with the default <code>Computer</code>. * * @param classes the classes containing the tests * @return a <code>Request</code> that will cause all tests in the classes to be run */ public static Request classes(Class<?>... classes) { return classes(JUnitCore.defaultComputer(), classes); }
/** * Creates a {@link Filter}. * * @param filterFactoryFqcn The fully qualified class name of the {@link FilterFactory} * @param params The arguments to the {@link FilterFactory} */ public static Filter createFilter(String filterFactoryFqcn, FilterFactoryParams params) throws FilterFactory.FilterNotCreatedException { FilterFactory filterFactory = createFilterFactory(filterFactoryFqcn); return filterFactory.createFilter(params); }
@RunWith(JUnit4.class) public class UnitTranscoderTest { @Test public void testReturnsTheGivenResource() { Resource<Object> resource = mockResource(); ResourceTranscoder<Object, Object> unitTranscoder = UnitTranscoder.get(); assertEquals(resource, unitTranscoder.transcode(resource, new Options())); } }
/** * Run all the tests in <code>classes</code>. * * @param computer Helps construct Runners from classes * @param classes the classes containing tests * @return a {@link Result} describing the details of the test run and the failed tests. */ public Result run(Computer computer, Class<?>... classes) { return run(Request.classes(computer, classes)); }
/** * @return the number of tests to be run by the receiver */ public int testCount() { return getDescription().testCount(); } }
/** * Create a <code>Request</code> that, when processed, will run all the tests * in a set of classes with the default <code>Computer</code>. * * @param classes the classes containing the tests * @return a <code>Request</code> that will cause all tests in the classes to be run */ public static Request classes(Class<?>... classes) { return classes(JUnitCore.defaultComputer(), classes); }
/** * Creates a {@link Filter}. * * @param filterFactoryClass The class of the {@link FilterFactory} * @param params The arguments to the {@link FilterFactory} * */ public static Filter createFilter(Class<? extends FilterFactory> filterFactoryClass, FilterFactoryParams params) throws FilterFactory.FilterNotCreatedException { FilterFactory filterFactory = createFilterFactory(filterFactoryClass); return filterFactory.createFilter(params); }
@RunWith(JUnit4.class) public class FileResourceTest { private File file; private FileResource resource; @Before public void setUp() { file = new File("Test"); resource = new FileResource(file); } @Test public void testReturnsGivenFile() { assertEquals(file, resource.get()); } }
@RunWith(AndroidJUnit4.class) public class EventBusAndroidCancelEventDeliveryTest extends EventBusCancelEventDeliveryTest { @UiThreadTest @Test public void testCancelInMainThread() { SubscriberMainThread subscriber = new SubscriberMainThread(); eventBus.register(subscriber); eventBus.post("42"); awaitLatch(subscriber.done, 10); assertEquals(0, eventCount.intValue()); assertNotNull(failed); } }
/** * @author Sam Brannen * @since 4.3 */ @RunWith(SpringRunner.class) public class BootstrapWithInterfaceTests implements BootstrapWithTestInterface { @Autowired String foo; @Test public void injectedBean() { assertEquals("foo", foo); } }
/** * @author Sam Brannen * @since 4.3 */ @RunWith(SpringRunner.class) public class WebAppConfigurationInterfaceTests implements WebAppConfigurationTestInterface { @Autowired WebApplicationContext wac; @Test public void wacLoaded() { assertNotNull(wac); } }