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.report;
12  
13  import static org.junit.jupiter.api.Assertions.assertEquals;
14  
15  import java.util.List;
16  
17  import org.junit.jupiter.api.Test;
18  
19  /**
20   * The Class RowReportTest.
21   */
22  class RowReportTest {
23  
24      /**
25       * Relevant block at start.
26       */
27      @Test
28      void relevantBlockAtStart() {
29          RowReport report = new RowReport("0123456789", 0, 4);
30          assertEquals(2, report.tokenize().size());
31          assertEquals("0123", report.tokenize().get(0).getToken());
32          assertEquals("456789", report.tokenize().get(1).getToken());
33      }
34  
35      /**
36       * Relevant block in middle.
37       */
38      @Test
39      void relevantBlockInMiddle() {
40          RowReport report = new RowReport("0123456789", 3, 6);
41          assertEquals(3, report.tokenize().size());
42          assertEquals("012", report.tokenize().get(0).getToken());
43          assertEquals("345", report.tokenize().get(1).getToken());
44          assertEquals("6789", report.tokenize().get(2).getToken());
45      }
46  
47      /**
48       * Relevant block at end.
49       */
50      @Test
51      void relevantBlockAtEnd() {
52          RowReport report = new RowReport("0123456789", 7, 10);
53          assertEquals(2, report.tokenize().size());
54          assertEquals("0123456", report.tokenize().get(0).getToken());
55          assertEquals("789", report.tokenize().get(1).getToken());
56      }
57  
58      /**
59       * Too small to notice.
60       */
61      @Test
62      void tooSmallToNotice() {
63          RowReport report = new RowReport("0123456789", 7, 7);
64          assertEquals(3, report.tokenize().size());
65          assertEquals("0123456", report.tokenize().get(0).getToken());
66          assertEquals("7", report.tokenize().get(1).getToken());
67          assertEquals("89", report.tokenize().get(2).getToken());
68      }
69  
70      /**
71       * Only at the end.
72       */
73      @Test
74      void onlyAtTheEnd() {
75          RowReport report = new RowReport("0123456789", 10, 10);
76          List<String> lines = report.getPrintableLines();
77          assertEquals("          ^", lines.get(1));
78      }
79  
80  }