1/*
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5
6package org.mockito.internal.runners;
7
8import org.junit.internal.runners.InitializationError;
9import org.junit.internal.runners.JUnit4ClassRunner;
10import org.junit.runner.Description;
11import org.junit.runner.manipulation.Filter;
12import org.junit.runner.manipulation.NoTestsRemainException;
13import org.junit.runner.notification.RunNotifier;
14import org.mockito.MockitoAnnotations;
15import org.mockito.internal.runners.util.FrameworkUsageValidator;
16
17@SuppressWarnings("deprecation")
18public class JUnit44RunnerImpl implements RunnerImpl {
19
20	JUnit4ClassRunner runner;
21
22    public JUnit44RunnerImpl(Class<?> klass) throws InitializationError {
23        this.runner = new JUnit4ClassRunner(klass) {
24            @Override
25            protected Object createTest() throws Exception {
26                Object test = super.createTest();
27                MockitoAnnotations.initMocks(test);
28                return test;
29            }
30        };
31    }
32
33    public void run(RunNotifier notifier) {
34        // add listener that validates framework usage at the end of each test
35        notifier.addListener(new FrameworkUsageValidator(notifier));
36
37        runner.run(notifier);
38    }
39
40    public Description getDescription() {
41        return runner.getDescription();
42    }
43
44	public void filter(Filter filter) throws NoTestsRemainException {
45		runner.filter(filter);
46	}
47}