/** * Constructs a new instance of the default runner */ public JUnit4(Class<?> klass) throws InitializationError { super(new TestClass(klass)); } }
/** * @deprecated Please use {@link #ParentRunner(org.junit.runners.model.TestClass)}. * @since 4.12 */ @Deprecated protected TestClass createTestClass(Class<?> testClass) { return new TestClass(testClass); }
parent p = new TestClass(); p.func(); // boom - func is public in parent, but TestClass's impl is private, so no access would be allowed
/** * Constructs a new {@code ParentRunner} that will run {@code @TestClass} */ protected ParentRunner(Class<?> testClass) throws InitializationError { fTestClass = new TestClass(testClass); validate(); }
private void invokeBeforeClass(final Class clazz) throws Throwable { if (!loadedTestClasses.contains(clazz)) { loadedTestClasses.add(clazz); final TestClass testClass = new TestClass(clazz); final List<FrameworkMethod> befores = testClass.getAnnotatedMethods(BeforeClass.class); for (FrameworkMethod before : befores) { before.invokeExplosively(null); } } }
private static void invokeAfterClass(final Class<?> clazz) throws Throwable { final TestClass testClass = new TestClass(clazz); final List<FrameworkMethod> afters = testClass.getAnnotatedMethods(AfterClass.class); for (FrameworkMethod after : afters) { after.invokeExplosively(null); } }
public void testTestClassParcelable(){ TestClass test = new TestClass(); // Obtain a Parcel object and write the parcelable object to it: Parcel parcel = Parcel.obtain(); test.writeToParcel(parcel, 0); // After you're done with writing, you need to reset the parcel for reading: parcel.setDataPosition(0); // Reconstruct object from parcel and asserts: TestClass createdFromParcel = TestClass.CREATOR.createFromParcel(parcel); assertEquals(test, createdFromParcel); }
/** * <p> * This method is package private (= visible) for testing. * </p> */ TestClass findDataProviderLocation(UseDataProvider useDataProvider) { if (useDataProvider.location().length == 0) { return getTestClassInt(); } return new TestClass(useDataProvider.location()[0]); }
private RunnersFactory(Class<?> klass) throws Throwable { testClass = new TestClass(klass); parametersMethod = getParametersMethod(testClass); List<Object> allParametersResult; AssumptionViolationRunner assumptionViolationRunner = null; try { allParametersResult = allParameters(testClass, parametersMethod); } catch (AssumptionViolatedException e) { allParametersResult = Collections.emptyList(); assumptionViolationRunner = new AssumptionViolationRunner(testClass, parametersMethod.getName(), e); } allParameters = allParametersResult; runnerOverride = assumptionViolationRunner; parameterCount = allParameters.isEmpty() ? 0 : normalizeParameters(allParameters.get(0)).length; }
private void initializeIfNecessary(FrameworkMethod method, final Object target) { final TestClass testClass = new TestClass(target.getClass()); OAuth2ContextConfiguration contextConfiguration = findOAuthContextConfiguration( method, testClass);
/** * Constructs a new {@code ParentRunner} that will run {@code @TestClass} */ protected ParentRunner(Class<?> testClass) throws InitializationError { fTestClass = new TestClass(testClass); validate(); }
/** * Creates a new fluent test rule. * * @param target target of the rule. */ public FluentTestRule(Object target) { this.target = target; testClass = new TestClass(target.getClass()); afters = testClass.getAnnotatedMethods(After.class); }
InnerClass innerClass = new TestClass().new InnerClass();
private static List<FrameworkMethod> getPrototypesMethods(Class<?> testClass) throws Exception { List<FrameworkMethod> methods = new TestClass(testClass).getAnnotatedMethods(Prototypes.class); if (methods.isEmpty()) { throw new Exception("No public static prototypes method on class " + testClass.getName()); } for (FrameworkMethod each : methods) { int modifiers = each.getMethod().getModifiers(); if (!Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) { throw new Exception(String.format("%s.%s() should be public static method: ", testClass.getName(), each.getName())); } } return methods; } }
private static List<FrameworkMethod> getPrototypesMethods(Class<?> testClass) throws Exception { List<FrameworkMethod> methods = new TestClass(testClass).getAnnotatedMethods(Prototypes.class); if (methods.isEmpty()) { throw new Exception("No public static prototypes method on class " + testClass.getName()); } for (FrameworkMethod each : methods) { int modifiers = each.getMethod().getModifiers(); if (!Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) { throw new Exception(String.format("%s.%s() should be public static method: ", testClass.getName(), each.getName())); } } return methods; } }
private static FrameworkMethod getAnnotatedMethod(ArtifactClassLoaderHolder artifactClassLoaderHolder, Class<?> isolatedTestClass, Class<? extends Annotation> annotationClass, String expectedParamType) throws ClassNotFoundException { TestClass testClass = new TestClass(isolatedTestClass); Class<? extends Annotation> artifactContextAwareAnn = (Class<? extends Annotation>) artifactClassLoaderHolder .loadClassWithATestRunnerClassLoader(annotationClass.getName()); List<FrameworkMethod> contextAwareMethods = testClass.getAnnotatedMethods(artifactContextAwareAnn); if (contextAwareMethods.size() != 1) { throw new IllegalStateException("Isolation tests need to have one method marked with annotation " + annotationClass.getName()); } final FrameworkMethod method = contextAwareMethods.get(0); if (!method.isStatic() || method.isPublic()) { throw new IllegalStateException("Method marked with annotation " + annotationClass.getName() + " should be private static and receive a parameter of type " + expectedParamType); } return method; }
public class MainActivity extends Activity implements Testeable { public void onCreate(){ TestClass mTestClass = new TestClass(this); } public testMethod(){ // do some work here } }
Holder(Class<? extends RunnerFeature> aType) throws InstantiationException, IllegalAccessException { type = aType; testClass = new TestClass(aType); feature = aType.newInstance(); }
TestClass t=new TestClass(); t.test=1; TestClass t1=t; t1.test=6; System.out.println(t.test); //prints 6.
private List<ClassInjectionRule> getClassInjectionRules(Description description) { return new TestClass(description.getTestClass()) .getAnnotatedFieldValues(null, ClassRule.class, ClassInjectionRule.class); } }