Package org.springframework.core.convert.support

Examples of org.springframework.core.convert.support.DefaultConversionService


  }

  @Test
  public void populatesConversionServiceCorrectly() {

    GenericConversionService conversionService = new DefaultConversionService();

    CustomConversions conversions = new CustomConversions(Arrays.asList(StringToFormatConverter.INSTANCE));
    conversions.registerConvertersIn(conversionService);

    assertThat(conversionService.canConvert(String.class, Format.class), is(true));
  }
View Full Code Here


   */
  @Test
  public void customConverterOverridesDefault() {

    CustomConversions conversions = new CustomConversions(Arrays.asList(CustomDateTimeConverter.INSTANCE));
    GenericConversionService conversionService = new DefaultConversionService();
    conversions.registerConvertersIn(conversionService);

    assertThat(conversionService.convert(new DateTime(), Date.class), is(new Date(0)));
  }
View Full Code Here

    }
  }

  private ConversionService getDefaultConversionService() {
    if (this.defaultConversionService == null) {
      DefaultConversionService conversionService = new DefaultConversionService();
      for (Converter<?, ?> converter : ((ListableBeanFactory) this.beanFactory)
          .getBeansOfType(Converter.class, false, false).values()) {
        conversionService.addConverter(converter);
      }
      this.defaultConversionService = conversionService;
    }
    return this.defaultConversionService;
  }
View Full Code Here

  }

  @Test
  public void testBindNestedListCommaDelimitedOnly() throws Exception {
    TargetWithNestedList target = new TargetWithNestedList();
    this.conversionService = new DefaultConversionService();
    bind(target, "nested: bar,foo");
    assertEquals("[bar, foo]", target.getNested().toString());
  }
View Full Code Here

  }

  @Test
  public void testBindNestedSetCommaDelimitedOnly() throws Exception {
    TargetWithNestedSet target = new TargetWithNestedSet();
    this.conversionService = new DefaultConversionService();
    bind(target, "nested: bar,foo");
    assertEquals("[bar, foo]", target.getNested().toString());
  }
View Full Code Here

  }

  @Test(expected = NotWritablePropertyException.class)
  public void testBindNestedReadOnlyListCommaSeparated() throws Exception {
    TargetWithReadOnlyNestedList target = new TargetWithReadOnlyNestedList();
    this.conversionService = new DefaultConversionService();
    bind(target, "nested: bar,foo");
    assertEquals("[bar, foo]", target.getNested().toString());
  }
View Full Code Here

  }

  @Test
  public void testBindNestedReadOnlyListIndexed() throws Exception {
    TargetWithReadOnlyNestedList target = new TargetWithReadOnlyNestedList();
    this.conversionService = new DefaultConversionService();
    bind(target, "nested[0]: bar\nnested[1]:foo");
    assertEquals("[bar, foo]", target.getNested().toString());
  }
View Full Code Here

  }

  @Test
  public void testBindDoubleNestedReadOnlyListIndexed() throws Exception {
    TargetWithReadOnlyDoubleNestedList target = new TargetWithReadOnlyDoubleNestedList();
    this.conversionService = new DefaultConversionService();
    bind(target, "bean.nested[0]:bar\nbean.nested[1]:foo");
    assertEquals("[bar, foo]", target.getBean().getNested().toString());
  }
View Full Code Here

  }

  @Test
  public void testBindNestedReadOnlyCollectionIndexed() throws Exception {
    TargetWithReadOnlyNestedCollection target = new TargetWithReadOnlyNestedCollection();
    this.conversionService = new DefaultConversionService();
    bind(target, "nested[0]: bar\nnested[1]:foo");
    assertEquals("[bar, foo]", target.getNested().toString());
  }
View Full Code Here

    assertEquals("123", target.getNested().get("value.foo"));
  }

  @Test
  public void testBindNestedMapOfEnum() throws Exception {
    this.conversionService = new DefaultConversionService();
    TargetWithNestedMapOfEnum target = new TargetWithNestedMapOfEnum();
    bind(target, "nested.this: bar\n" + "nested.ThAt: 123");
    assertEquals("bar", target.getNested().get(Bingo.THIS));
    assertEquals("123", target.getNested().get(Bingo.THAT));
  }
View Full Code Here

TOP

Related Classes of org.springframework.core.convert.support.DefaultConversionService

Copyright © 2018 www.massapicom. 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.