1 | /*
|
---|
2 | * To change this template, choose Tools | Templates
|
---|
3 | * and open the template in the editor.
|
---|
4 | */
|
---|
5 | package gov.hhs.fha.nhinc.util.format;
|
---|
6 |
|
---|
7 | import gov.hhs.fha.nhinc.nhinclib.NullChecker;
|
---|
8 | import java.util.List;
|
---|
9 | import org.junit.AfterClass;
|
---|
10 | import org.junit.BeforeClass;
|
---|
11 | import org.junit.Test;
|
---|
12 | import static org.junit.Assert.*;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | *
|
---|
16 | * @author rayj
|
---|
17 | */
|
---|
18 | public class DocumentClassCodeParserTest {
|
---|
19 |
|
---|
20 | public DocumentClassCodeParserTest() {
|
---|
21 | }
|
---|
22 |
|
---|
23 | @BeforeClass
|
---|
24 | public static void setUpClass() throws Exception {
|
---|
25 | }
|
---|
26 |
|
---|
27 | @AfterClass
|
---|
28 | public static void tearDownClass() throws Exception {
|
---|
29 | }
|
---|
30 |
|
---|
31 | @Test
|
---|
32 | public void SingleItemFormattedTest1() {
|
---|
33 | String input = "('1')";
|
---|
34 | int expectedResultSize = 1;
|
---|
35 | String expectedOutputList = "1";
|
---|
36 | PerformTest(input, expectedResultSize, expectedOutputList);
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Test
|
---|
40 | public void SingleItemNotFormattedTest() {
|
---|
41 | String input = "1";
|
---|
42 | int expectedResultSize = 1;
|
---|
43 | String expectedOutputList = "1";
|
---|
44 | PerformTest(input, expectedResultSize, expectedOutputList);
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Test
|
---|
48 | public void MultipleItemsTest() {
|
---|
49 | String input = "('1,2,3')";
|
---|
50 | int expectedResultSize = 3;
|
---|
51 | String expectedOutputList = "1,2,3";
|
---|
52 | PerformTest(input, expectedResultSize, expectedOutputList);
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Test
|
---|
56 | public void MultipleItemsTest2() {
|
---|
57 | String input = "('aa,bb,cc')";
|
---|
58 | int expectedResultSize = 3;
|
---|
59 | String expectedOutputList = "aa,bb,cc";
|
---|
60 | PerformTest(input, expectedResultSize, expectedOutputList);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Test
|
---|
64 | public void NullInput() {
|
---|
65 | String input = null;
|
---|
66 | int expectedResultSize = 0;
|
---|
67 | String expectedOutputList = null;
|
---|
68 | PerformTest(input, expectedResultSize, expectedOutputList);
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Test
|
---|
72 | public void EmptyInput() {
|
---|
73 | String input = "";
|
---|
74 | int expectedResultSize = 0;
|
---|
75 | String expectedOutputList = null;
|
---|
76 | PerformTest(input, expectedResultSize, expectedOutputList);
|
---|
77 | }
|
---|
78 |
|
---|
79 | private void PerformTest(String input, int expectedResultSize, String expectedResultList) {
|
---|
80 | List<String> result = DocumentClassCodeParser.parseFormattedParameter(input);
|
---|
81 | assertNotNull(result);
|
---|
82 | assertEquals(expectedResultSize, result.size());
|
---|
83 | String resultList = null;
|
---|
84 | for (String item : result) {
|
---|
85 | if (NullChecker.isNotNullish(item)) {
|
---|
86 | if (resultList == null) {
|
---|
87 | resultList = item;
|
---|
88 | } else {
|
---|
89 | resultList = resultList + "," + item;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | }
|
---|
93 |
|
---|
94 | assertEquals(expectedResultList, resultList);
|
---|
95 | }
|
---|
96 | }
|
---|