### Question:
OSGiStartProcessEngineStep extends StartProcessEngineStep { @Override @SuppressWarnings("unchecked") protected <T> Class<? extends T> loadClass(String className, ClassLoader customClassloader, Class<T> clazz) { Class<? extends T> configurationClass = null; if(customClassloader != null) { try { configurationClass = (Class<? extends T>) customClassloader.loadClass(className); } catch(ClassNotFoundException e) { } } if(customClassloader == null || configurationClass == null) { configurationClass = (Class<? extends T>) ReflectUtil.loadClass(className); } return configurationClass; } OSGiStartProcessEngineStep(ProcessEngineXml processEngineXml, BundleContext context);   }### Answer:
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void loadClassWithCustomClassloader() throws ClassNotFoundException{ OSGiStartProcessEngineStep step = new OSGiStartProcessEngineStep(mock(ProcessEngineXml.class), mock(BundleContext.class)); ClassLoader classLoader = mock(ClassLoader.class); String clazz = "org.foo.Bar"; when(classLoader.loadClass(clazz)).thenReturn((Class) this.getClass()); Class<? extends Object> loadedClazz = step.loadClass(clazz, classLoader, null); assertThat(loadedClazz.getName(), is(this.getClass().getName())); }
@Test public void loadClassWithNullCustomClassloader() throws ClassNotFoundException{ OSGiStartProcessEngineStep step = new OSGiStartProcessEngineStep(mock(ProcessEngineXml.class), mock(BundleContext.class)); String clazz = "java.lang.Object"; Class<? extends Object> loadedClazz = step.loadClass(clazz, null, null); assertThat(loadedClazz.getName(), is(Object.class.getName())); }
@Test public void loadClassWithExceptionInCustomClassloader() throws ClassNotFoundException{ OSGiStartProcessEngineStep step = new OSGiStartProcessEngineStep(mock(ProcessEngineXml.class), mock(BundleContext.class)); String clazz = "java.lang.Object"; ClassLoader classLoader = mock(ClassLoader.class); when(classLoader.loadClass(clazz)).thenThrow(new ClassNotFoundException()); Class<? extends Object> loadedClazz = step.loadClass(clazz, null, null); assertThat(loadedClazz.getName(), is(Object.class.getName())); }