1 /* 2 * Copyright (c) 2007 Mockito contributors 3 * This program is made available under the terms of the MIT License. 4 */ 5 package org.mockito.internal.runners.util; 6 7 import java.lang.reflect.Constructor; 8 import java.lang.reflect.InvocationTargetException; 9 10 import org.mockito.internal.runners.RunnerImpl; 11 12 public class RunnerProvider { 13 14 private static boolean hasJUnit45OrHigher; 15 16 static { 17 try { 18 Class.forName("org.junit.runners.BlockJUnit4ClassRunner"); 19 hasJUnit45OrHigher = true; 20 } catch (Throwable t) { 21 hasJUnit45OrHigher = false; 22 } 23 } 24 isJUnit45OrHigherAvailable()25 public boolean isJUnit45OrHigherAvailable() { 26 return hasJUnit45OrHigher; 27 } 28 newInstance(String runnerClassName, Class<?> constructorParam)29 public RunnerImpl newInstance(String runnerClassName, Class<?> constructorParam) throws Exception { 30 Constructor<?> constructor; 31 try { 32 Class<?> runnerClass = Class.forName(runnerClassName); 33 constructor = runnerClass.getConstructor(Class.class.getClass()); 34 } catch (Exception e) { 35 throw new RuntimeException(e); 36 } 37 38 try { 39 return (RunnerImpl) constructor.newInstance(constructorParam); 40 } catch (InvocationTargetException e) { 41 throw e; 42 } catch (Exception e) { 43 throw new RuntimeException(e); 44 } 45 } 46 }