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.assertEquals;
14  import static org.junit.jupiter.api.Assertions.assertNotNull;
15  import static org.junit.jupiter.api.Assertions.assertNull;
16  import static org.junit.jupiter.api.Assertions.assertTrue;
17  
18  import java.beans.IntrospectionException;
19  import java.beans.PropertyDescriptor;
20  
21  import org.csveed.bean.conversion.Converter;
22  import org.csveed.test.converters.BeanSimpleConverter;
23  import org.csveed.test.model.BeanSimple;
24  import org.csveed.test.model.BeanVariousNotAnnotated;
25  import org.junit.jupiter.api.Test;
26  
27  /**
28   * The Class BeanPropertyTest.
29   */
30  class BeanPropertyTest {
31  
32      /**
33       * Construct.
34       *
35       * @throws IntrospectionException
36       *             the introspection exception
37       */
38      @Test
39      void construct() throws IntrospectionException {
40          BeanProperty property = new BeanProperty();
41          Converter<BeanSimple> converter = new BeanSimpleConverter();
42          PropertyDescriptor propertyDescriptor = new PropertyDescriptor("name", BeanSimple.class);
43          property.setConverter(converter);
44          property.setColumnIndex(3);
45          property.setColumnName("name");
46          property.setPropertyDescriptor(propertyDescriptor);
47          property.setRequired(true);
48          assertEquals(converter, property.getConverter());
49          assertEquals(3, property.getColumnIndex());
50          assertEquals("name", property.getColumnName());
51          assertEquals(propertyDescriptor, property.getPropertyDescriptor());
52          assertTrue(property.isRequired());
53      }
54  
55      /**
56       * Number class.
57       *
58       * @throws IntrospectionException
59       *             the introspection exception
60       */
61      @Test
62      void numberClass() throws IntrospectionException {
63          BeanProperty property = new BeanProperty();
64          property.setPropertyDescriptor(new PropertyDescriptor("number", BeanVariousNotAnnotated.class));
65          assertNotNull(property.getNumberClass());
66      }
67  
68      /**
69       * Not A number class.
70       *
71       * @throws IntrospectionException
72       *             the introspection exception
73       */
74      @Test
75      void notANumberClass() throws IntrospectionException {
76          BeanProperty property = new BeanProperty();
77          property.setPropertyDescriptor(new PropertyDescriptor("name", BeanSimple.class));
78          assertNull(property.getNumberClass());
79      }
80  
81  }