예제 #1
0
 @Test
 public void testCaseInsensitive() throws Exception {
   List<CaseInsensitiveRecord> objs =
       CsvDeserializer.deserialize("NAME,CAMELCASEVALUE\nname,not!", CaseInsensitiveRecord.class);
   Assert.assertNull("hi", objs.get(0).name);
   Assert.assertEquals("not!", objs.get(0).camelCasevalue);
 }
예제 #2
0
  @Test
  public void testEnum() throws Exception {
    List<EnumExample> objs = CsvDeserializer.deserialize("id,name\n42,EXAMPLE", EnumExample.class);

    Assert.assertEquals(42, objs.get(0).getId().intValue());
    Assert.assertEquals(EnumExample.Name.EXAMPLE, objs.get(0).getName());
  }
예제 #3
0
  @Test
  public void testSimpleRecord() throws Exception {
    List<SimpleRecord> objs =
        CsvDeserializer.deserialize("id,name\n42,example", SimpleRecord.class);

    Assert.assertEquals(42, objs.get(0).getId().intValue());
    Assert.assertEquals("example", objs.get(0).getName());
  }
예제 #4
0
  @Test
  public void testDeserializationPreprocessor() throws Exception {
    List<DeserializationPreprocessorExample> objs =
        CsvDeserializer.deserialize("id,name\n,", DeserializationPreprocessorExample.class);

    Assert.assertTrue(0 == objs.get(0).getId());
    Assert.assertNull(objs.get(0).getName());
  }
예제 #5
0
  @Test
  public void testIgnoreGarbage() throws Exception {
    List<IgnoreGarbageExample> objs =
        CsvDeserializer.deserialize("id,name\n42,example\nfhh97gh34k3", IgnoreGarbageExample.class);

    Assert.assertEquals(42, objs.get(0).getId().intValue());
    Assert.assertEquals("example", objs.get(0).getName());
  }
예제 #6
0
  @Test
  public void testRenaming() throws Exception {
    List<RenamingExample> objs =
        CsvDeserializer.deserialize("internalId,n\n42,example", RenamingExample.class);

    Assert.assertEquals(42, objs.get(0).getId().intValue());
    Assert.assertEquals("example", objs.get(0).getName());
  }
예제 #7
0
  @Test
  public void testDefaultRecordDelimiter() throws Exception {
    List<SimpleRecord> objs =
        CsvDeserializer.deserialize(
            new StringReader("id,name\r\n42,example"), SimpleRecord.class, ',', null);

    Assert.assertEquals(42, objs.get(0).getId().intValue());
    Assert.assertEquals("example", objs.get(0).getName());
  }
예제 #8
0
  @Test
  public void testFieldDelimiter() throws Exception {
    List<SimpleRecord> objs =
        CsvDeserializer.deserialize(
            new StringReader("id|name\n42|example"), SimpleRecord.class, '|', '\n');

    Assert.assertEquals(42, objs.get(0).getId().intValue());
    Assert.assertEquals("example", objs.get(0).getName());
  }
예제 #9
0
  @Test
  public void testIgnoreForSerialization() throws Exception {
    List<IgnoreForSerializationExample> objs =
        CsvDeserializer.deserialize(
            "id,name,foo\n42,example,bar", IgnoreForSerializationExample.class);

    Assert.assertNull(objs.get(0).getName());
    Assert.assertNull(objs.get(0).getFoo());
  }
예제 #10
0
  private void doEncodingTest(Charset charset) throws Exception {
    String value = "\u00f1example\u00f1";
    String fullCsv = "name\n" + value;

    List<SimpleRecord> objs =
        CsvDeserializer.deserialize(
            new InputStreamReader(new ByteArrayInputStream(fullCsv.getBytes(charset)), charset),
            SimpleRecord.class);

    Assert.assertEquals(value, objs.get(0).getName());
  }
예제 #11
0
  @Test
  public void testProvidedHeaders() throws Exception {
    List<SimpleRecord> objs =
        CsvDeserializer.deserialize(
            new StringReader("42,example"),
            SimpleRecord.class,
            ',',
            '\n',
            ImmutableList.<String>of("id", "name"));

    Assert.assertEquals(42, objs.get(0).getId().intValue());
    Assert.assertEquals("example", objs.get(0).getName());
  }
예제 #12
0
 @Test(expected = NullPointerException.class)
 public void testNullReader() throws Exception {
   CsvDeserializer.deserialize((Reader) null, String.class);
 }
예제 #13
0
 @Test(expected = NullPointerException.class)
 public void testNullString() throws Exception {
   CsvDeserializer.deserialize((String) null, SimpleRecord.class);
 }
예제 #14
0
 @Test(expected = DeserializingException.class)
 public void testNoDefaultConstructor() throws Exception {
   CsvDeserializer.deserialize("id\n5", NoDefaultConstructorExample.class);
 }
예제 #15
0
 @Test(expected = DeserializingException.class)
 public void testStaticMemeber() throws Exception {
   CsvDeserializer.deserialize("name\nexample", StaticMemberExample.class);
 }
예제 #16
0
 /**
  * Passing means not throwing an exception
  *
  * @throws Exception
  */
 @Test
 public void testIgnoredFinalMemeber() throws Exception {
   CsvDeserializer.deserialize("id\n5", IgnoredFinalMemberExample.class);
 }
예제 #17
0
 @Test(expected = DeserializingException.class)
 public void testFinalMemeber() throws Exception {
   CsvDeserializer.deserialize("id\n5", FinalMemberExample.class);
 }
예제 #18
0
 @Test(expected = DeserializingException.class)
 public void testUnparsable() throws Exception {
   CsvDeserializer.deserialize("a,b,,,d\n1\n\n,,,,,,,,,,,,,,,,", SimpleRecord.class);
 }