@Test public void shouldConvertStringToObject() throws Exception { Set<ConvertiblePair> types = converter.getConvertibleTypes(); assertEquals(1, types.size()); ConvertiblePair pair = types.iterator().next(); assertEquals(String.class, pair.getSourceType()); assertEquals(Object.class, pair.getTargetType()); }
@Test public void shouldReThrowFacesException() throws Exception { TypeDescriptor targetType = AnnotatedClass.getFieldTypeDescriptor(); reset(application); given(application.createConverter("example")).willThrow(new FacesException()); thrown.expect(FacesException.class); converter.convert(source, sourceType, targetType); }
@Test public void shouldThrowIfNoConverter() throws Exception { TypeDescriptor targetType = AnnotatedClass.getFieldTypeDescriptor(); reset(application); thrown.expect(IllegalStateException.class); thrown.expectMessage("No JSF converter located for ID 'example'"); converter.convert(source, sourceType, targetType); }
@Test public void shouldMatchIfConverterExists() throws Exception { TypeDescriptor targetType = TypeDescriptor.valueOf(ClassWithConverter.class); assertTrue(converter.matches(sourceType, targetType)); }
@Test public void shouldMatchIfHasAnnotationOnMethod() throws Exception { TypeDescriptor targetType = AnnotatedClass.getMethodParamTypeDescriptor(); assertTrue(converter.matches(sourceType, targetType)); }
@Test public void shouldNotMatchIfNotSpringFacesContext() throws Exception { SpringFacesContextSetter.setCurrentInstance(null); assertFalse(converter.matches(sourceType, TypeDescriptor.valueOf(Object.class))); }
@Test public void shouldConvertByType() throws Exception { TypeDescriptor targetType = TypeDescriptor.valueOf(ClassWithConverter.class); assertEquals(converted, converter.convert(source, sourceType, targetType)); }
@Test public void shouldConvertAnnotationOnMethod() throws Exception { TypeDescriptor targetType = AnnotatedClass.getMethodParamTypeDescriptor(); assertEquals(converted, converter.convert(source, sourceType, targetType)); }
@Test public void shouldConvertNull() throws Exception { assertNull(converter.convert(null, sourceType, TypeDescriptor.forObject(Object.class))); }