Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / misc / xgen / src / test / java / org / onap / aaf / misc / xgen / html / JU_HTML5GenTest.java
1 /**\r
2  * ============LICENSE_START====================================================\r
3  * org.onap.aaf\r
4  * ===========================================================================\r
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
6  * ===========================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END====================================================\r
19  *\r
20  */\r
21 package org.onap.aaf.misc.xgen.html;\r
22 \r
23 import static org.mockito.Matchers.anyInt;\r
24 import static org.mockito.Mockito.atLeast;\r
25 import static org.mockito.Mockito.mock;\r
26 import static org.mockito.Mockito.verify;\r
27 \r
28 import java.io.IOException;\r
29 import java.io.Writer;\r
30 import java.util.Map;\r
31 import java.util.TreeMap;\r
32 \r
33 import org.junit.Before;\r
34 import org.junit.Test;\r
35 import org.mockito.Mock;\r
36 \r
37 public class JU_HTML5GenTest {\r
38 \r
39 //    private final static String DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\""\r
40 //            + " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";\r
41 \r
42     private String charset = "utf-8";\r
43 \r
44     private final String CHARSET_LINE = "<meta charset=\"" + charset + "\">";\r
45 \r
46     @Mock\r
47     Writer w;\r
48 \r
49     @Before\r
50     public void setUp() throws Exception {\r
51 \r
52         w = mock(Writer.class);\r
53     }\r
54 \r
55     @Test\r
56     public void testHTML() throws IOException {\r
57 \r
58         HTML5Gen gen = new HTML5Gen(w);\r
59 \r
60         gen.html("attributes");\r
61 \r
62         Map<Character, Integer> map = new TreeMap<>();\r
63 \r
64         for (char ch : "html".toCharArray()) {\r
65             Integer times = map.get(ch);\r
66             map.put(ch, (times == null ? 0 : times) + 1);\r
67         }\r
68 \r
69         for (char ch : map.keySet()) {\r
70             verify(w, atLeast(map.get(ch))).write(ch);\r
71         }\r
72         verify(w, atLeast(1)).write(anyInt());\r
73     }\r
74 \r
75     @Test\r
76     public void testHead() throws IOException {\r
77 \r
78         HTML5Gen gen = new HTML5Gen(w);\r
79 \r
80         gen.head();\r
81 \r
82         Map<Character, Integer> map = new TreeMap<>();\r
83 \r
84         for (char ch : "head".toCharArray()) {\r
85             Integer times = map.get(ch);\r
86             map.put(ch, (times == null ? 0 : times) + 1);\r
87         }\r
88 \r
89         for (char ch : map.keySet()) {\r
90             verify(w, atLeast(map.get(ch))).write(ch);\r
91         }\r
92     }\r
93 \r
94     @Test\r
95     public void testBody() throws IOException {\r
96 \r
97         HTML5Gen gen = new HTML5Gen(w);\r
98 \r
99         gen.body("attributes");\r
100 \r
101         Map<Character, Integer> map = new TreeMap<>();\r
102 \r
103         for (char ch : "body".toCharArray()) {\r
104             Integer times = map.get(ch);\r
105             map.put(ch, (times == null ? 0 : times) + 1);\r
106         }\r
107         for (char ch : "attributes".toCharArray()) {\r
108             Integer times = map.get(ch);\r
109             map.put(ch, (times == null ? 0 : times) + 1);\r
110         }\r
111 \r
112         for (char ch : map.keySet()) {\r
113             verify(w, atLeast(map.get(ch))).write(ch);\r
114         }\r
115     }\r
116 \r
117     @Test\r
118     public void testCharSet() throws IOException {\r
119 \r
120         HTML5Gen gen = new HTML5Gen(w);\r
121 \r
122         gen.charset(charset);\r
123 \r
124         Map<Character, Integer> map = new TreeMap<>();\r
125 \r
126         for (char ch : CHARSET_LINE.toCharArray()) {\r
127             Integer times = map.get(ch);\r
128             map.put(ch, (times == null ? 0 : times) + 1);\r
129         }\r
130 \r
131         for (char ch : map.keySet()) {\r
132             verify(w, atLeast(map.get(ch))).write(ch);\r
133         }\r
134     }\r
135 }\r