Converters { static <T> Converter<T> getConverter(Scope scope, Class<T> parameterType) { return getConverter(scope, parameterType, EMPTY_ANNOTATIONS); } private  Converters();   }
@Test public void shouldRetrieveConfiguredConverter() throws NoSuchMethodException { final SomeBeanConverter someBeanConverter = new SomeBeanConverter(); final Scope scope = new SingleBeanScope<>(SomeBeanConverter.class, someBeanConverter); final Method method = ConvertersTest.class.getDeclaredMethod("methodWithConvertedParameter", SomeBean.class); final Converter<SomeBean> converter = Converters.getConverter(scope, SomeBean.class, method.getParameterAnnotations()[0]); Assert.assertNotNull("should not be null", converter); Assert.assertEquals("should be retrieved from scope", someBeanConverter, converter); }
@Test public void shouldRetrieveDefaultConverter() { final Scope scope = new EmptyScope(); final Converter<Integer> converter = Converters.getConverter(scope, Integer.class); Assert.assertNotNull("should not be null", converter); final int value = converter.convert("123"); Assert.assertEquals("should convert integers", 123, value); }
@Test(expected = NumberFormatException.class) public void shouldThrowOnPrimitiveNullParameter() { final Scope scope = new EmptyScope(); final Converter<Integer> converter = Converters.getConverter(scope, Integer.TYPE); converter.convert(null); }
@Test public void shouldConvertNullableParameter() { final Scope scope = new EmptyScope(); final Converter<Integer> converter = Converters.getConverter(scope, Integer.class); Integer value = converter.convert(null); Assert.assertNull("should support null value", value); }