Package org.springframework.core.convert

Examples of org.springframework.core.convert.ConversionService.canConvert()


  @Test
  public void createDefaultConversionService() {
    ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
    factory.afterPropertiesSet();
    ConversionService service = factory.getObject();
    assertTrue(service.canConvert(String.class, Integer.class));
  }

  @Test
  public void createDefaultConversionServiceWithSupplements() {
    ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
View Full Code Here


      }
    });
    factory.setConverters(converters);
    factory.afterPropertiesSet();
    ConversionService service = factory.getObject();
    assertTrue(service.canConvert(String.class, Integer.class));
    assertTrue(service.canConvert(String.class, Foo.class));
    assertTrue(service.canConvert(String.class, Bar.class));
    assertTrue(service.canConvert(String.class, Baz.class));
  }
View Full Code Here

    });
    factory.setConverters(converters);
    factory.afterPropertiesSet();
    ConversionService service = factory.getObject();
    assertTrue(service.canConvert(String.class, Integer.class));
    assertTrue(service.canConvert(String.class, Foo.class));
    assertTrue(service.canConvert(String.class, Bar.class));
    assertTrue(service.canConvert(String.class, Baz.class));
  }

  @Test(expected=IllegalArgumentException.class)
View Full Code Here

    factory.setConverters(converters);
    factory.afterPropertiesSet();
    ConversionService service = factory.getObject();
    assertTrue(service.canConvert(String.class, Integer.class));
    assertTrue(service.canConvert(String.class, Foo.class));
    assertTrue(service.canConvert(String.class, Bar.class));
    assertTrue(service.canConvert(String.class, Baz.class));
  }

  @Test(expected=IllegalArgumentException.class)
  public void createDefaultConversionServiceWithInvalidSupplements() {
View Full Code Here

    factory.afterPropertiesSet();
    ConversionService service = factory.getObject();
    assertTrue(service.canConvert(String.class, Integer.class));
    assertTrue(service.canConvert(String.class, Foo.class));
    assertTrue(service.canConvert(String.class, Bar.class));
    assertTrue(service.canConvert(String.class, Baz.class));
  }

  @Test(expected=IllegalArgumentException.class)
  public void createDefaultConversionServiceWithInvalidSupplements() {
    ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean();
View Full Code Here

  }

  @Test
  public void testWithConversionService() {
    ConversionService conversionService = new DefaultConversionService();
    assertTrue(conversionService.canConvert(String.class, MimeType.class));
    MimeType mimeType = MimeType.valueOf("application/xml");
    assertEquals(mimeType, conversionService.convert("application/xml", MimeType.class));
  }

  @Test
View Full Code Here

    // No custom editor but custom ConversionService specified?
    ConversionService conversionService = this.propertyEditorRegistry.getConversionService();
    if (editor == null && conversionService != null && convertedValue != null) {
      TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(convertedValue);
      if (conversionService.canConvert(sourceTypeDesc, typeDescriptor)) {
        return (T) conversionService.convert(convertedValue, sourceTypeDesc, typeDescriptor);
      }
    }

    // Value not of required type?
View Full Code Here

    // No custom editor but custom ConversionService specified?
    ConversionService conversionService = this.propertyEditorRegistry.getConversionService();
    if (editor == null && conversionService != null && convertedValue != null) {
      TypeDescriptor sourceTypeDesc = TypeDescriptor.forObject(convertedValue);
      TypeDescriptor targetTypeDesc = typeDescriptor.forElementType(requiredType);
      if (conversionService.canConvert(sourceTypeDesc, targetTypeDesc)) {
        return (T) conversionService.convert(convertedValue, sourceTypeDesc, targetTypeDesc);
      }
    }

    // Value not of required type?
View Full Code Here

    }
    @Test
    public void injectionForConversionService() {
        final Config config = assertInjected("-conversion");
        final ConversionService conversionService = config.neo4jTemplate.getConversionService();
        assertEquals(true, conversionService.canConvert(Enum.class,String.class));
        assertEquals(true, conversionService.canConvert(Config.class, Integer.class));
    }

    private Config assertInjected(String testCase) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:org/springframework/data/neo4j/config/DataGraphNamespaceHandlerTests" + testCase + "-context.xml");
View Full Code Here

    @Test
    public void injectionForConversionService() {
        final Config config = assertInjected("-conversion");
        final ConversionService conversionService = config.neo4jTemplate.getConversionService();
        assertEquals(true, conversionService.canConvert(Enum.class,String.class));
        assertEquals(true, conversionService.canConvert(Config.class, Integer.class));
    }

    private Config assertInjected(String testCase) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:org/springframework/data/neo4j/config/DataGraphNamespaceHandlerTests" + testCase + "-context.xml");
        try {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.