2727import org .junit .Before ;
2828import org .junit .BeforeClass ;
2929import org .junit .Test ;
30- import org .spdx .licenseTemplate .*;
30+ import org .spdx .licenseTemplate .LicenseParserException ;
31+ import org .spdx .licenseTemplate .LicenseTemplateRule ;
32+ import org .spdx .licenseTemplate .LicenseTemplateRuleException ;
33+ import org .spdx .licenseTemplate .SpdxLicenseTemplateHelper ;
3134import org .spdx .licenseTemplate .LicenseTemplateRule .RuleType ;
35+ import org .spdx .licenseTemplate .LineColumn ;
3236
3337/**
3438 * Test compare template output handler
@@ -49,12 +53,12 @@ public class TestCompareTemplateOutputHandler {
4953 static final String APACHE_1_0_TEMPLATE = "TestFiles" + File .separator + "Apache-1.0.template.txt" ;
5054 static final String BSD_2_CLAUSE_TEXT = "TestFiles" + File .separator + "BSD-2-Clause.txt" ;
5155 static final String BSD_2_CLAUSE_TEMPLATE = "TestFiles" + File .separator + "BSD-2-Clause.template.txt" ;
52- static final String BSD_4_CLAUSE_UC_TEXT = "TestFiles" + File .separator + "BSD-4-Clause-UC.txt" ;
53- static final String BSD_4_CLAUSE_UC_TEMPLATE = "TestFiles" + File .separator + "BSD-4-Clause-UC.template.txt" ;
54- static final String BSD_4_CLAUSE_TEXT = "TestFiles" + File .separator + "BSD-4-Clause.txt" ;
55- static final String BSD_4_CLAUSE_TEMPLATE = "TestFiles" + File .separator + "BSD-4-Clause.template.txt" ;
56- static final String CROSSWORD_TEXT = "TestFiles" + File .separator + "Crossword.txt" ;
57- static final String CROSSWORD_TEMPLATE = "TestFiles" + File .separator + "Crossword.template.txt" ;
56+ static final String BSD_4_CLAUSE_UC_TEXT = "TestFiles" + File .separator + "BSD-4-Clause-UC.txt" ;
57+ static final String BSD_4_CLAUSE_UC_TEMPLATE = "TestFiles" + File .separator + "BSD-4-Clause-UC.template.txt" ;
58+ static final String BSD_4_CLAUSE_TEXT = "TestFiles" + File .separator + "BSD-4-Clause.txt" ;
59+ static final String BSD_4_CLAUSE_TEMPLATE = "TestFiles" + File .separator + "BSD-4-Clause.template.txt" ;
60+ static final String CROSSWORD_TEXT = "TestFiles" + File .separator + "Crossword.txt" ;
61+ static final String CROSSWORD_TEMPLATE = "TestFiles" + File .separator + "Crossword.template.txt" ;
5862 static final String DFSL_TEXT = "TestFiles" + File .separator + "D-FSL-1.0.txt" ;
5963 static final String DFSL_TEMPLATE = "TestFiles" + File .separator + "D-FSL-1.0.template.txt" ;
6064 static final String CONDOR_1_1_TEXT = "TestFiles" + File .separator + "Condor-1.1.txt" ;
@@ -124,7 +128,6 @@ public void tearDown() throws Exception {
124128
125129 /**
126130 * Test method for {@link org.spdx.compare.CompareTemplateOutputHandler#CompareTemplateOutputHandler(java.lang.String)}.
127- *
128131 * @throws Exception
129132 */
130133 @ Test
@@ -136,57 +139,56 @@ public void testCompareTemplateOutputHandler() throws Exception {
136139
137140 /**
138141 * Test method for {@link org.spdx.compare.CompareTemplateOutputHandler#text(java.lang.String)}.
139- *
140142 * @throws LicenseTemplateRuleException
141143 */
142144 @ Test
143- public void testOptionalText () throws Exception {
145+ public void testOptionalText () throws Exception {
144146 String l1 = "Line 1\n " ;
145147 String l2 = "Line 2\n " ;
146148 String l3 = "Line 3\n " ;
147149 String l4 = "Line 4" ;
148150 // optional in middle
149- String compareText = l1 + l4 ;
151+ String compareText = l1 + l4 ;
150152 CompareTemplateOutputHandler ctoh = new CompareTemplateOutputHandler (compareText );
151153 ctoh .text (l1 );
152154 ctoh .beginOptional (new LicenseTemplateRule ("OptionalRule" , RuleType .BEGIN_OPTIONAL ));
153155 ctoh .text (l2 );
154156 ctoh .text (l3 );
155- ctoh .endOptional (new LicenseTemplateRule ("EndOptional" , RuleType .END_OPTIONAL ));
157+ ctoh .endOptional (new LicenseTemplateRule ("EndOptional" ,RuleType .END_OPTIONAL ));
156158 ctoh .text (l4 );
157159 ctoh .completeParsing ();
158160 assertTrue (ctoh .matches ());
159161
160162 // optional at beginning
161- compareText = l3 + l4 ;
163+ compareText = l3 + l4 ;
162164 ctoh = new CompareTemplateOutputHandler (compareText );
163165 ctoh .beginOptional (new LicenseTemplateRule ("OptionalRule" , RuleType .BEGIN_OPTIONAL ));
164166 ctoh .text (l1 );
165167 ctoh .text (l2 );
166- ctoh .endOptional (new LicenseTemplateRule ("EndOptional" , RuleType .END_OPTIONAL ));
168+ ctoh .endOptional (new LicenseTemplateRule ("EndOptional" ,RuleType .END_OPTIONAL ));
167169 ctoh .text (l3 );
168170 ctoh .text (l4 );
169171 ctoh .completeParsing ();
170172 assertTrue (ctoh .matches ());
171173 // optional at end
172- compareText = l1 + l2 + l3 ;
174+ compareText = l1 + l2 + l3 ;
173175 ctoh = new CompareTemplateOutputHandler (compareText );
174176 ctoh .text (l1 );
175177 ctoh .text (l2 );
176178 ctoh .text (l3 );
177179 ctoh .beginOptional (new LicenseTemplateRule ("OptionalRule" , RuleType .BEGIN_OPTIONAL ));
178180 ctoh .text (l4 );
179- ctoh .endOptional (new LicenseTemplateRule ("EndOptional" , RuleType .END_OPTIONAL ));
181+ ctoh .endOptional (new LicenseTemplateRule ("EndOptional" ,RuleType .END_OPTIONAL ));
180182 ctoh .completeParsing ();
181183 assertTrue (ctoh .matches ());
182184 // optional code present
183- compareText = l1 + l2 + l3 + l4 ;
185+ compareText = l1 + l2 + l3 + l4 ;
184186 ctoh = new CompareTemplateOutputHandler (compareText );
185187 ctoh .text (l1 );
186188 ctoh .beginOptional (new LicenseTemplateRule ("OptionalRule" , RuleType .BEGIN_OPTIONAL ));
187189 ctoh .text (l2 );
188190 ctoh .text (l3 );
189- ctoh .endOptional (new LicenseTemplateRule ("EndOptional" , RuleType .END_OPTIONAL ));
191+ ctoh .endOptional (new LicenseTemplateRule ("EndOptional" ,RuleType .END_OPTIONAL ));
190192 ctoh .text (l4 );
191193 ctoh .completeParsing ();
192194 assertTrue (ctoh .matches ());
@@ -204,33 +206,33 @@ public void testTextEquivalent() throws Exception {
204206 String l2R = "## Line 2 with replaceable analog canceled stuff\n " ;
205207 String l3 = "Line\n " ;
206208 String l4 = "Line 4" ;
207- String compareText = l1 + l2 + l3 + l4 ;
209+ String compareText = l1 + l2 + l3 + l4 ;
208210 CompareTemplateOutputHandler ctoh = new CompareTemplateOutputHandler (compareText );
209- int nextToken = ctoh .textEquivalent (l1 , 0 );
211+ int nextToken = ctoh .textEquivalent (l1 ,0 );
210212 assertTrue (nextToken > 0 );
211- assertTrue ((nextToken = ctoh .textEquivalent (l2 , nextToken )) > 0 );
212- assertTrue ((nextToken = ctoh .textEquivalent (l3 , nextToken )) > 0 );
213- assertTrue ((nextToken = ctoh .textEquivalent (l4 , nextToken )) > 0 );
213+ assertTrue ((nextToken = ctoh .textEquivalent (l2 ,nextToken )) > 0 );
214+ assertTrue ((nextToken = ctoh .textEquivalent (l3 ,nextToken )) > 0 );
215+ assertTrue ((nextToken = ctoh .textEquivalent (l4 ,nextToken )) > 0 );
214216 // after end of compare string
215- assertTrue ((nextToken = ctoh .textEquivalent (l4 , nextToken )) < 0 );
217+ assertTrue ((nextToken = ctoh .textEquivalent (l4 ,nextToken )) < 0 );
216218
217219 // difference in string
218220 ctoh = new CompareTemplateOutputHandler (compareText );
219- assertTrue ((nextToken = ctoh .textEquivalent (l4 , 0 )) < 0 );
221+ assertTrue ((nextToken = ctoh .textEquivalent (l4 ,0 )) < 0 );
220222
221223 // skippable tokens
222224 ctoh = new CompareTemplateOutputHandler (compareText );
223- assertTrue ((nextToken = ctoh .textEquivalent (l1S , 0 )) > 0 );
224- assertTrue ((nextToken = ctoh .textEquivalent (l2S , nextToken )) > 0 );
225- assertTrue ((nextToken = ctoh .textEquivalent (l3 , nextToken )) > 0 );
226- assertTrue ((nextToken = ctoh .textEquivalent (l4 , nextToken )) > 0 );
225+ assertTrue ((nextToken = ctoh .textEquivalent (l1S ,0 )) > 0 );
226+ assertTrue ((nextToken = ctoh .textEquivalent (l2S ,nextToken )) > 0 );
227+ assertTrue ((nextToken = ctoh .textEquivalent (l3 ,nextToken )) > 0 );
228+ assertTrue ((nextToken = ctoh .textEquivalent (l4 ,nextToken )) > 0 );
227229
228230 // equivalent tokens
229231 ctoh = new CompareTemplateOutputHandler (compareText );
230- assertTrue ((nextToken = ctoh .textEquivalent (l1 , 0 )) > 0 );
231- assertTrue ((nextToken = ctoh .textEquivalent (l2R , nextToken )) > 0 );
232- assertTrue ((nextToken = ctoh .textEquivalent (l3 , nextToken )) > 0 );
233- assertTrue ((nextToken = ctoh .textEquivalent (l4 , nextToken )) > 0 );
232+ assertTrue ((nextToken = ctoh .textEquivalent (l1 ,0 )) > 0 );
233+ assertTrue ((nextToken = ctoh .textEquivalent (l2R ,nextToken )) > 0 );
234+ assertTrue ((nextToken = ctoh .textEquivalent (l3 ,nextToken )) > 0 );
235+ assertTrue ((nextToken = ctoh .textEquivalent (l4 ,nextToken )) > 0 );
234236 }
235237
236238 /**
@@ -270,11 +272,10 @@ public void testNormalText() throws Exception {
270272
271273 /**
272274 * Test method for {@link org.spdx.compare.CompareTemplateOutputHandler#variableRule(org.spdx.licenseTemplate.LicenseTemplateRule)}.
273- *
274275 * @throws LicenseTemplateRuleException
275276 */
276277 @ Test
277- public void testVariableRule () throws Exception {
278+ public void testVariableRule () throws Exception {
278279 String line1 = "this is line one\n " ;
279280 String line2 = "this line 2 is another line\n " ;
280281 String line2Match = "this\\ sline\\ s.+another\\ sline" ;
@@ -286,7 +287,7 @@ public void testVariableRule() throws Exception {
286287 CompareTemplateOutputHandler ctoh = new CompareTemplateOutputHandler (compareText );
287288 ctoh .text (line1 );
288289 LicenseTemplateRule variableRule = new LicenseTemplateRule ("Variable Rule" ,
289- RuleType .VARIABLE , line2 , line2Match , "Example: " + line2 );
290+ RuleType .VARIABLE , line2 , line2Match , "Example: " + line2 );
290291 ctoh .variableRule (variableRule );
291292 ctoh .text (line3 );
292293 ctoh .completeParsing ();
@@ -297,7 +298,7 @@ public void testVariableRule() throws Exception {
297298 ctoh = new CompareTemplateOutputHandler (partialCompareText );
298299 ctoh .text (line1 );
299300 variableRule = new LicenseTemplateRule ("Variable Rule" ,
300- RuleType .VARIABLE , line2 , line2Match , "Example: " + line2 );
301+ RuleType .VARIABLE , line2 , line2Match , "Example: " + line2 );
301302 ctoh .variableRule (variableRule );
302303 ctoh .completeParsing ();
303304 assertTrue (ctoh .matches ());
@@ -306,7 +307,7 @@ public void testVariableRule() throws Exception {
306307 ctoh = new CompareTemplateOutputHandler (compareText );
307308 ctoh .text (line1 );
308309 variableRule = new LicenseTemplateRule ("Variable Rule" ,
309- RuleType .VARIABLE , line2 , line2MissMatch , "Example: " + line2 );
310+ RuleType .VARIABLE , line2 , line2MissMatch , "Example: " + line2 );
310311 ctoh .variableRule (variableRule );
311312 ctoh .text (line3 );
312313 ctoh .completeParsing ();
@@ -315,7 +316,7 @@ public void testVariableRule() throws Exception {
315316 // Extra word
316317 ctoh = new CompareTemplateOutputHandler (compareText );
317318 variableRule = new LicenseTemplateRule ("Variable Rule" ,
318- RuleType .VARIABLE , line2 , line2PartialMatch , "Example: " + line2 );
319+ RuleType .VARIABLE , line2 , line2PartialMatch , "Example: " + line2 );
319320 ctoh .variableRule (variableRule );
320321 ctoh .text (line3 );
321322 ctoh .completeParsing ();
@@ -657,7 +658,9 @@ public void testCompareAlphabetVarDiffMessage() throws IOException, LicenseTempl
657658 String compareText = "a b\t c d e f g h i j k l m n o p\n q r s t u v w x y z end" ;
658659 CompareTemplateOutputHandler templateOutputHandler = new CompareTemplateOutputHandler (compareText );
659660 SpdxLicenseTemplateHelper .parseTemplate (templateText , templateOutputHandler );
661+
660662 System .out .println (templateOutputHandler .getDifferences ().getDifferenceMessage ());
663+
661664 if (templateOutputHandler .matches ()) {
662665 fail (templateOutputHandler .getDifferences ().getDifferenceMessage ());
663666 }
0 commit comments