ConfigBuilder { protected <T> T instantiate(Class<T> clazz) { if (clazz == null) { return null; }else{ try { return ComponentFactory.instantiate(clazz, crestConfig); } catch (Exception e) { throw CRestException.handle(e); } } } ConfigBuilder(CRestConfig crestConfig); CRestConfig getCRestConfig(); T override(String property, T defaultIfNotFound);  }
@Test public void instanciateShouldReturnNullIfGivenNull() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { assertNull(toTest.instantiate(null)); }
@Test public void instanciateShouldDelegateToComponentFactory() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { mockStatic(ComponentFactory.class); when(ComponentFactory.instantiate(String.class, mockCRestConfig)).thenReturn("a"); String actual = toTest.instantiate(String.class); assertEquals("a", actual); }
@Test public void instanciateShouldDelegateAnyExceptionToCRestHandle() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException { RuntimeException expected = mock(RuntimeException.class); InvocationTargetException e = mock(InvocationTargetException.class); mockStatic(ComponentFactory.class); when(ComponentFactory.instantiate(String.class, mockCRestConfig)).thenThrow(e); mockStatic(CRestException.class); when(CRestException.handle((Exception)e)).thenReturn(expected); try { toTest.instantiate(String.class); fail(); } catch (Exception e1) { assertSame(expected, e1); } }