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.assertFalse;
14  import static org.junit.jupiter.api.Assertions.assertTrue;
15  
16  import org.csveed.common.Column;
17  import org.junit.jupiter.api.Test;
18  
19  /**
20   * The Class DynamicColumnTest.
21   */
22  class DynamicColumnTest {
23  
24      /**
25       * Advance and reset.
26       */
27      @Test
28      void advanceAndReset() {
29          int startColumn = 5;
30          int numberOfColumns = 7;
31          DynamicColumn column = new DynamicColumn(new Column(startColumn));
32          for (int i = 0; i < numberOfColumns - startColumn + 1; i++) {
33              column.advanceDynamicColumn();
34              assertFalse(column.atFirstDynamicColumn(), "Must not be at first column now");
35              column.checkForReset(numberOfColumns);
36          }
37          assertTrue(column.atFirstDynamicColumn(), "Must be at first dynamic column now");
38      }
39  
40      /**
41       * We have no dynamic columns.
42       */
43      @Test
44      void weHaveNoDynamicColumns() {
45          DynamicColumn column = new DynamicColumn(null);
46          column.advanceDynamicColumn(); // should have no effect
47          assertTrue(column.atFirstDynamicColumn(), "Must be at first dynamic column now"); // always the case if empty
48      }
49  
50      /**
51       * Active dynamic columns.
52       */
53      @Test
54      void activeDynamicColumns() {
55          Column activeColumn = new Column(4);
56          Column inactiveColumn = new Column(5);
57          DynamicColumn dynamicColumn = new DynamicColumn(activeColumn);
58          assertTrue(dynamicColumn.isDynamicColumnActive(activeColumn),
59                  "Column " + activeColumn.getColumnIndex() + " must be active");
60          assertFalse(dynamicColumn.isDynamicColumnActive(inactiveColumn),
61                  "Column " + inactiveColumn.getColumnIndex() + " must be active");
62      }
63  }