View Javadoc
1   /*
2    * CSVeed (https://github.com/42BV/CSVeed)
3    *
4    * Copyright 2013-2023 CSVeed.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of The Apache Software License,
8    * Version 2.0 which accompanies this distribution, and is available at
9    * https://www.apache.org/licenses/LICENSE-2.0.txt
10   */
11  package org.csveed.bean;
12  
13  import static org.junit.jupiter.api.Assertions.assertNotNull;
14  import static org.junit.jupiter.api.Assertions.assertNull;
15  import static org.junit.jupiter.api.Assertions.assertThrows;
16  
17  import org.csveed.common.Column;
18  import org.csveed.report.CsvException;
19  import org.csveed.test.model.BeanLotsOfIgnores;
20  import org.csveed.test.model.BeanWithWrongAnnotation;
21  import org.csveed.test.model.BeanWithoutGettersAndSetters;
22  import org.junit.jupiter.api.Test;
23  
24  /**
25   * The Class BeanParserTest.
26   */
27  class BeanParserTest {
28  
29      /**
30       * No getters and setters.
31       */
32      @Test
33      void noGettersAndSetters() {
34          BeanParser beanParser = new BeanParser();
35          BeanInstructions instructions = beanParser.getBeanInstructions(BeanWithoutGettersAndSetters.class);
36          assertNull(instructions.getProperties().fromName(new Column("a")));
37      }
38  
39      /**
40       * Case insensitivity.
41       */
42      @Test
43      void caseInsensitivity() {
44          BeanParser beanParser = new BeanParser();
45          BeanInstructions instructions = beanParser.getBeanInstructions(BeanLotsOfIgnores.class);
46          assertNotNull(instructions.getProperties().fromName(new Column("takeThis1")));
47          assertNotNull(instructions.getProperties().fromName(new Column("takethis1")));
48      }
49  
50      /**
51       * Wrong annotation.
52       */
53      @Test
54      void wrongAnnotation() {
55          BeanParser beanParser = new BeanParser();
56          assertThrows(CsvException.class, () -> beanParser.getBeanInstructions(BeanWithWrongAnnotation.class));
57      }
58  
59  }