ExternalInitializer { public <T> T loadExternalClass(final String externalClassName, final String classPath, final Class<T> interfaceToCast) { T result; try { result = externalClassInitializer.loadExternalClass(externalClassName, classPath, interfaceToCast); } catch (DescriptorValidationFailedException dvfe) { logger.info("Couldn't initialize external class: '{}'", dvfe.getMessage()); String jarFolderPath = stubResourcePathProvider.getJarPathAsString(); result = externalJarClassInitializer.loadExternalClass(externalClassName, jarFolderPath, interfaceToCast); } return result; }  T loadExternalClass(final String externalClassName, final String classPath, final Class<T> interfaceToCast);  }
@Test public void testLoadExternalClassShouldLoadFromExternalClassInitializerFirst() { given(externalClassInitializer.loadExternalClass(EXTERNAL_CLASS_NAME, CLASS_PATH, INTERFACE_TO_CAST)).willReturn(new Object()); Object result = underTest.loadExternalClass(EXTERNAL_CLASS_NAME, CLASS_PATH, INTERFACE_TO_CAST); assertNotNull(result); verify(externalJarClassInitializer, never()).loadExternalClass(EXTERNAL_CLASS_NAME, CLASS_PATH, INTERFACE_TO_CAST); }
@Test public void testWhenExternalClassInitializerCannotLoadClassThenExternalJarClassInitializerShouldTryToLoadClass() { given(externalClassInitializer.loadExternalClass(EXTERNAL_CLASS_NAME, CLASS_PATH, INTERFACE_TO_CAST)).willThrow( new DescriptorValidationFailedException("")); given(stubResourcePathProvider.getJarPathAsString()).willReturn("path/jar"); underTest.loadExternalClass(EXTERNAL_CLASS_NAME, CLASS_PATH, INTERFACE_TO_CAST); verify(externalJarClassInitializer).loadExternalClass(EXTERNAL_CLASS_NAME, "path/jar", INTERFACE_TO_CAST); }