Search in sources :

Example 6 with DbPrimitiveObjectWithSetter

use of org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter in project SimpleFlatMapper by arnaudroger.

the class PrimitivesDelayedCellSetterTest method testIntGetSetValue.

@Test
public void testIntGetSetValue() throws Exception {
    Setter<DbPrimitiveObjectWithSetter, Integer> intSetter = objectSetterFactory.getSetter(DbPrimitiveObjectWithSetter.class, "pInt");
    IntDelayedCellSetter<DbPrimitiveObjectWithSetter> setter = new IntDelayedCellSetter<DbPrimitiveObjectWithSetter>(ObjectSetterFactory.toIntSetter(intSetter), new IntegerCellValueReaderImpl());
    setter.set("13".toCharArray(), 0, 2, null);
    assertEquals(new Integer(13), setter.consumeValue());
    setter.set("13".toCharArray(), 0, 2, null);
    DbPrimitiveObjectWithSetter o = new DbPrimitiveObjectWithSetter();
    setter.set(o);
    assertEquals(13, o.getpInt());
    setter.set("".toCharArray(), 0, 0, null);
    assertNull(setter.consumeValue());
}
Also used : DbPrimitiveObjectWithSetter(org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter) IntDelayedCellSetter(org.simpleflatmapper.csv.impl.primitive.IntDelayedCellSetter) Test(org.junit.Test)

Example 7 with DbPrimitiveObjectWithSetter

use of org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter in project SimpleFlatMapper by arnaudroger.

the class PrimitivesDelayedCellSetterTest method testShortGetSetValue.

@Test
public void testShortGetSetValue() throws Exception {
    Setter<DbPrimitiveObjectWithSetter, Short> shortSetter = objectSetterFactory.getSetter(DbPrimitiveObjectWithSetter.class, "pShort");
    ShortDelayedCellSetter<DbPrimitiveObjectWithSetter> setter = new ShortDelayedCellSetter<DbPrimitiveObjectWithSetter>(ObjectSetterFactory.toShortSetter(shortSetter), new ShortCellValueReaderImpl());
    setter.set("13".toCharArray(), 0, 2, null);
    assertEquals(new Short((short) 13), setter.consumeValue());
    setter.set("13".toCharArray(), 0, 2, null);
    DbPrimitiveObjectWithSetter o = new DbPrimitiveObjectWithSetter();
    setter.set(o);
    assertEquals((short) 13, o.getpShort());
    setter.set("".toCharArray(), 0, 0, null);
    assertNull(setter.consumeValue());
}
Also used : DbPrimitiveObjectWithSetter(org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter) ShortDelayedCellSetter(org.simpleflatmapper.csv.impl.primitive.ShortDelayedCellSetter) Test(org.junit.Test)

Example 8 with DbPrimitiveObjectWithSetter

use of org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter in project SimpleFlatMapper by arnaudroger.

the class PrimitivesDelayedCellSetterTest method testDoubleGetSetValue.

@Test
public void testDoubleGetSetValue() throws Exception {
    Setter<DbPrimitiveObjectWithSetter, Double> doubleSetter = objectSetterFactory.getSetter(DbPrimitiveObjectWithSetter.class, "pDouble");
    DoubleDelayedCellSetter<DbPrimitiveObjectWithSetter> setter = new DoubleDelayedCellSetter<DbPrimitiveObjectWithSetter>(ObjectSetterFactory.toDoubleSetter(doubleSetter), new DoubleCellValueReaderImpl());
    setter.set("13".toCharArray(), 0, 2, null);
    assertEquals(new Double(13), setter.consumeValue());
    setter.set("13".toCharArray(), 0, 2, null);
    DbPrimitiveObjectWithSetter o = new DbPrimitiveObjectWithSetter();
    setter.set(o);
    assertEquals(13, o.getpDouble(), 0);
    setter.set("".toCharArray(), 0, 0, null);
    assertNull(setter.consumeValue());
}
Also used : DbPrimitiveObjectWithSetter(org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter) DoubleDelayedCellSetter(org.simpleflatmapper.csv.impl.primitive.DoubleDelayedCellSetter) Test(org.junit.Test)

Example 9 with DbPrimitiveObjectWithSetter

use of org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter in project SimpleFlatMapper by arnaudroger.

the class PrimitivesDelayedCellSetterTest method testByteGetSetValue.

@Test
public void testByteGetSetValue() throws Exception {
    Setter<DbPrimitiveObjectWithSetter, Byte> byteSetter = objectSetterFactory.getSetter(DbPrimitiveObjectWithSetter.class, "pByte");
    ByteDelayedCellSetter<DbPrimitiveObjectWithSetter> setter = new ByteDelayedCellSetter<DbPrimitiveObjectWithSetter>(ObjectSetterFactory.toByteSetter(byteSetter), new ByteCellValueReaderImpl());
    setter.set("13".toCharArray(), 0, 2, null);
    assertEquals(new Byte((byte) 13), setter.consumeValue());
    setter.set("13".toCharArray(), 0, 2, null);
    DbPrimitiveObjectWithSetter o = new DbPrimitiveObjectWithSetter();
    setter.set(o);
    assertEquals((byte) 13, o.getpByte());
    setter.set("".toCharArray(), 0, 0, null);
    assertNull(setter.consumeValue());
}
Also used : DbPrimitiveObjectWithSetter(org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter) ByteDelayedCellSetter(org.simpleflatmapper.csv.impl.primitive.ByteDelayedCellSetter) Test(org.junit.Test)

Example 10 with DbPrimitiveObjectWithSetter

use of org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter in project SimpleFlatMapper by arnaudroger.

the class FieldMapperToAppendableFactoryTest method testDoubleWithFormatterAppender.

@Test
public void testDoubleWithFormatterAppender() throws Exception {
    MappingContextFactoryBuilder<DbPrimitiveObjectWithSetter, CsvColumnKey> builder = getMappingContextBuilder();
    FieldMapperColumnDefinition<CsvColumnKey> format = FieldMapperColumnDefinition.<CsvColumnKey>identity().add(new FormatProperty(new DecimalFormat("0.0")));
    FieldMapper<DbPrimitiveObjectWithSetter, Appendable> fieldMapper = defaultFieldAppenderFactory.newFieldMapper(newPropertyMapping("pDouble", dbPrimitiveObjectClassMeta, format), builder, null);
    testFieldMapper("3.1", fieldMapper, dbPrimitiveObject, builder.newFactory());
}
Also used : DbPrimitiveObjectWithSetter(org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter) FormatProperty(org.simpleflatmapper.map.property.FormatProperty) DateFormatProperty(org.simpleflatmapper.map.property.DateFormatProperty) DecimalFormat(java.text.DecimalFormat) CsvColumnKey(org.simpleflatmapper.csv.CsvColumnKey) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 DbPrimitiveObjectWithSetter (org.simpleflatmapper.test.beans.DbPrimitiveObjectWithSetter)10 DecimalFormat (java.text.DecimalFormat)1 CsvColumnKey (org.simpleflatmapper.csv.CsvColumnKey)1 BooleanDelayedCellSetter (org.simpleflatmapper.csv.impl.primitive.BooleanDelayedCellSetter)1 ByteDelayedCellSetter (org.simpleflatmapper.csv.impl.primitive.ByteDelayedCellSetter)1 CharDelayedCellSetter (org.simpleflatmapper.csv.impl.primitive.CharDelayedCellSetter)1 DoubleDelayedCellSetter (org.simpleflatmapper.csv.impl.primitive.DoubleDelayedCellSetter)1 FloatDelayedCellSetter (org.simpleflatmapper.csv.impl.primitive.FloatDelayedCellSetter)1 IntDelayedCellSetter (org.simpleflatmapper.csv.impl.primitive.IntDelayedCellSetter)1 LongDelayedCellSetter (org.simpleflatmapper.csv.impl.primitive.LongDelayedCellSetter)1 ShortDelayedCellSetter (org.simpleflatmapper.csv.impl.primitive.ShortDelayedCellSetter)1 DateFormatProperty (org.simpleflatmapper.map.property.DateFormatProperty)1 FormatProperty (org.simpleflatmapper.map.property.FormatProperty)1 ConstantSourceFieldMapperFactoryImplTest (org.simpleflatmapper.test.map.fieldmapper.ConstantSourceFieldMapperFactoryImplTest)1