1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sourceforge.plantumldependency.cli.main.option.programminglanguage.context.impl;
26
27 import static java.util.Arrays.asList;
28 import static java.util.regex.Pattern.compile;
29 import static net.sourceforge.plantumldependency.cli.constants.PlantUMLDependencyConstants.DEFAULT_DISPLAY_NAME_OPTIONS_PATTERN;
30 import static net.sourceforge.plantumldependency.cli.constants.PlantUMLDependencyConstants.DEFAULT_DISPLAY_PACKAGE_NAME_OPTIONS_PATTERN;
31 import static net.sourceforge.plantumldependency.cli.constants.PlantUMLDependencyConstants.DEFAULT_DISPLAY_TYPES_OPTIONS;
32 import static net.sourceforge.plantumldependency.cli.constants.PlantUMLDependencyDisplaySetTestConstants.DISPLAY_TYPE_SET3;
33 import static net.sourceforge.plantumldependency.cli.main.option.display.type.argument.DisplayType.ABSTRACT_CLASSES;
34 import static net.sourceforge.plantumldependency.cli.main.option.display.type.argument.DisplayType.DISPLAY_TYPES_OPTIONS;
35 import static net.sourceforge.plantumldependency.cli.plantumldiagram.classes.impl.PlantUMLClassesDiagramImplTest.PLANTUML_CLASSES_DIAGRAM_TEST2;
36 import static org.junit.Assert.assertEquals;
37 import static org.junit.Assert.assertNotNull;
38 import static org.junit.Assert.assertNull;
39 import static org.junit.Assert.assertTrue;
40
41 import java.util.TreeSet;
42
43 import net.sourceforge.plantumldependency.cli.generic.GenericDependency;
44 import net.sourceforge.plantumldependency.cli.generic.impl.GenericDependencyImpl;
45 import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.PlantUMLClassesDiagramElement;
46 import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.element.impl.PlantUMLClassesDiagramClassElementImpl;
47 import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.impl.PlantUMLClassesDiagramImpl;
48 import net.sourceforge.plantumldependency.cli.plantumldiagram.classes.relation.PlantUMLClassesDiagramRelation;
49 import net.sourceforge.plantumldependency.common.ComparableAndDeepCloneableObjectTest;
50
51 import org.junit.Test;
52 import org.junit.experimental.theories.DataPoint;
53
54
55
56
57
58
59
60
61 public class JavaProgrammingLanguageContextTest extends
62 ComparableAndDeepCloneableObjectTest < JavaProgrammingLanguageContextTest > {
63
64
65 @DataPoint
66 public static final JavaProgrammingLanguageContext JAVA_PROGRAMMING_LANGUAGE_CONTEXT1 = new JavaProgrammingLanguageContext();
67
68
69 @DataPoint
70 public static final JavaProgrammingLanguageContext JAVA_PROGRAMMING_LANGUAGE_CONTEXT2 = new JavaProgrammingLanguageContext(
71 new TreeSet < GenericDependency >(asList(new GenericDependency[] {
72 new GenericDependencyImpl("TestReadDependencyFromFileInterfaceWithoutPackage",
73 "net.sourceforge.plantumldependency.main.option.programminglanguage"),
74 new GenericDependencyImpl("GenericDependency", "net.sourceforge.plantumldependency.generic")})),
75 DEFAULT_DISPLAY_TYPES_OPTIONS, DEFAULT_DISPLAY_PACKAGE_NAME_OPTIONS_PATTERN,
76 DEFAULT_DISPLAY_NAME_OPTIONS_PATTERN);
77
78
79 @DataPoint
80 public static final JavaProgrammingLanguageContext JAVA_PROGRAMMING_LANGUAGE_CONTEXT3 = new JavaProgrammingLanguageContext(
81 new TreeSet < GenericDependency >(asList(new GenericDependency[] {
82 new GenericDependencyImpl("TestReadDependencyFromFileInterfaceWithoutPackage",
83 "net.sourceforge.plantumldependency.main.option.programminglanguage"),
84 new GenericDependencyImpl("GenericDependency", "net.sourceforge.plantumldependency.generic")})),
85 DISPLAY_TYPE_SET3, DEFAULT_DISPLAY_PACKAGE_NAME_OPTIONS_PATTERN, DEFAULT_DISPLAY_NAME_OPTIONS_PATTERN);
86
87
88 @DataPoint
89 public static final JavaProgrammingLanguageContext JAVA_PROGRAMMING_LANGUAGE_CONTEXT4 = new JavaProgrammingLanguageContext(
90 new TreeSet < GenericDependency >(asList(new GenericDependency[] {
91 new GenericDependencyImpl("TestReadDependencyFromFileInterfaceWithoutPackage",
92 "net.sourceforge.plantumldependency.main.option.programminglanguage"),
93 new GenericDependencyImpl("GenericDependency", "net.sourceforge.plantumldependency.generic")})),
94 new TreeSet < GenericDependency >(asList(new GenericDependency[] {new GenericDependencyImpl(
95 "GenericDependency", "net.sourceforge.plantumldependency.generic")})),
96 new TreeSet < GenericDependency >(asList(new GenericDependency[] {new GenericDependencyImpl(
97 "TestReadDependencyFromFileInterfaceWithoutPackage",
98 "net.sourceforge.plantumldependency.main.option.programminglanguage")})), DISPLAY_TYPES_OPTIONS,
99 DEFAULT_DISPLAY_PACKAGE_NAME_OPTIONS_PATTERN, DEFAULT_DISPLAY_NAME_OPTIONS_PATTERN);
100
101
102 @DataPoint
103 public static final JavaProgrammingLanguageContext JAVA_PROGRAMMING_LANGUAGE_CONTEXT5 = new JavaProgrammingLanguageContext(
104 new TreeSet < GenericDependency >(asList(new GenericDependency[] {
105 new GenericDependencyImpl("TestReadDependencyFromFileInterfaceWithoutPackage",
106 "net.sourceforge.plantumldependency.main.option.programminglanguage"),
107 new GenericDependencyImpl("GenericDependency", "net.sourceforge.plantumldependency.generic")})),
108 new TreeSet < GenericDependency >(asList(new GenericDependency[] {new GenericDependencyImpl(
109 "GenericDependency", "net.sourceforge.plantumldependency.generic")})), DISPLAY_TYPES_OPTIONS,
110 DEFAULT_DISPLAY_PACKAGE_NAME_OPTIONS_PATTERN, DEFAULT_DISPLAY_NAME_OPTIONS_PATTERN);
111
112
113 @DataPoint
114 public static final JavaProgrammingLanguageContext JAVA_PROGRAMMING_LANGUAGE_CONTEXT6 = new JavaProgrammingLanguageContext(
115 new TreeSet < GenericDependency >(asList(new GenericDependency[] {
116 new GenericDependencyImpl("TestReadDependencyFromFileInterfaceWithoutPackage",
117 "net.sourceforge.plantumldependency.main.option.programminglanguage"),
118 new GenericDependencyImpl("GenericDependency", "net.sourceforge.plantumldependency.generic")})),
119 DEFAULT_DISPLAY_TYPES_OPTIONS, compile(".*main.*"), DEFAULT_DISPLAY_NAME_OPTIONS_PATTERN);
120
121
122 @DataPoint
123 public static final JavaProgrammingLanguageContext JAVA_PROGRAMMING_LANGUAGE_CONTEXT7 = new JavaProgrammingLanguageContext(
124 new TreeSet < GenericDependency >(asList(new GenericDependency[] {
125 new GenericDependencyImpl("TestReadDependencyFromFileInterfaceWithoutPackage",
126 "net.sourceforge.plantumldependency.main.option.programminglanguage"),
127 new GenericDependencyImpl("GenericDependency", "net.sourceforge.plantumldependency.generic")})),
128 new TreeSet < GenericDependency >(asList(new GenericDependency[] {new GenericDependencyImpl(
129 "GenericDependency", "net.sourceforge.plantumldependency.generic")})),
130 new TreeSet < GenericDependency >(asList(new GenericDependency[] {new GenericDependencyImpl(
131 "TestReadDependencyFromFileInterfaceWithoutPackage",
132 "net.sourceforge.plantumldependency.main.option.programminglanguage")})), DISPLAY_TYPES_OPTIONS,
133 DEFAULT_DISPLAY_PACKAGE_NAME_OPTIONS_PATTERN, compile(".*Package"));
134
135
136 @DataPoint
137 public static final JavaProgrammingLanguageContext JAVA_PROGRAMMING_LANGUAGE_CONTEXT8 = new JavaProgrammingLanguageContext();
138
139
140 @DataPoint
141 public static final JavaProgrammingLanguageContext JAVA_PROGRAMMING_LANGUAGE_CONTEXT9 = null;
142
143
144
145
146
147
148 @Test
149 public void testAddParsedAndSeenDependenciesWithExistingDependency() {
150 final JavaProgrammingLanguageContext javaProgrammingLanguageContext = (JavaProgrammingLanguageContext) JAVA_PROGRAMMING_LANGUAGE_CONTEXT2
151 .deepClone();
152 javaProgrammingLanguageContext.addParsedAndSeenDependencies(new GenericDependencyImpl(
153 "TestReadDependencyFromFileInterfaceWithoutPackage",
154 "net.sourceforge.plantumldependency.main.option.programminglanguage"));
155 assertEquals(2, javaProgrammingLanguageContext.getParsedAndSeenDependencies().size());
156 assertEquals(2, javaProgrammingLanguageContext.getParsedDependencies().size());
157 }
158
159
160
161
162
163
164 @Test
165 public void testAddParsedAndSeenDependenciesWithNotExistingDependency() {
166 final JavaProgrammingLanguageContext javaProgrammingLanguageContext = (JavaProgrammingLanguageContext) JAVA_PROGRAMMING_LANGUAGE_CONTEXT2
167 .deepClone();
168 javaProgrammingLanguageContext.addParsedAndSeenDependencies(new GenericDependencyImpl("DeepCloneable",
169 "net.sourceforge.mazix.components.clone"));
170 assertEquals(3, javaProgrammingLanguageContext.getParsedAndSeenDependencies().size());
171 assertEquals(3, javaProgrammingLanguageContext.getParsedDependencies().size());
172 }
173
174
175
176
177
178
179 @Test
180 public void testAddPotentialJavaLangSeenDependenciesWithExistingDependency() {
181 final JavaProgrammingLanguageContext javaProgrammingLanguageContext = (JavaProgrammingLanguageContext) JAVA_PROGRAMMING_LANGUAGE_CONTEXT4
182 .deepClone();
183 javaProgrammingLanguageContext.addPotentialJavaLangSeenDependencies(new GenericDependencyImpl(
184 "TestReadDependencyFromFileInterfaceWithoutPackage",
185 "net.sourceforge.plantumldependency.main.option.programminglanguage"));
186 assertEquals(2, javaProgrammingLanguageContext.getParsedAndSeenDependencies().size());
187 assertEquals(1, javaProgrammingLanguageContext.getPotentialJavaLangSeenDependencies().size());
188 }
189
190
191
192
193
194
195 @Test
196 public void testAddPotentialJavaLangSeenDependenciesWithNotExistingDependency() {
197 final JavaProgrammingLanguageContext javaProgrammingLanguageContext = (JavaProgrammingLanguageContext) JAVA_PROGRAMMING_LANGUAGE_CONTEXT4
198 .deepClone();
199 javaProgrammingLanguageContext.addPotentialJavaLangSeenDependencies(new GenericDependencyImpl("DeepCloneable",
200 "net.sourceforge.mazix.components.clone"));
201 assertEquals(3, javaProgrammingLanguageContext.getParsedAndSeenDependencies().size());
202 assertEquals(2, javaProgrammingLanguageContext.getPotentialJavaLangSeenDependencies().size());
203 }
204
205
206
207
208
209
210 @Test
211 public void testAddSeenDependenciesWithExistingDependency() {
212 final JavaProgrammingLanguageContext javaProgrammingLanguageContext = (JavaProgrammingLanguageContext) JAVA_PROGRAMMING_LANGUAGE_CONTEXT2
213 .deepClone();
214 javaProgrammingLanguageContext.addSeenDependencies(new GenericDependencyImpl(
215 "TestReadDependencyFromFileInterfaceWithoutPackage",
216 "net.sourceforge.plantumldependency.main.option.programminglanguage"));
217 assertEquals(2, javaProgrammingLanguageContext.getParsedAndSeenDependencies().size());
218 assertEquals(2, javaProgrammingLanguageContext.getParsedDependencies().size());
219 }
220
221
222
223
224
225
226 @Test
227 public void testAddSeenDependenciesWithNotExistingDependency() {
228 final JavaProgrammingLanguageContext javaProgrammingLanguageContext = (JavaProgrammingLanguageContext) JAVA_PROGRAMMING_LANGUAGE_CONTEXT2
229 .deepClone();
230 javaProgrammingLanguageContext.addSeenDependencies(new GenericDependencyImpl("DeepCloneable",
231 "net.sourceforge.mazix.components.clone"));
232 assertEquals(3, javaProgrammingLanguageContext.getParsedAndSeenDependencies().size());
233 assertEquals(2, javaProgrammingLanguageContext.getParsedDependencies().size());
234 }
235
236
237
238
239
240
241 @Test
242 public void testGetAllDependencies() {
243 assertEquals(2, JAVA_PROGRAMMING_LANGUAGE_CONTEXT2.getParsedAndSeenDependencies().size());
244 }
245
246
247
248
249
250
251 @Test
252 public void testGetParsedOrSeenDependencyWithExistingDependency() {
253 assertEquals(
254 new GenericDependencyImpl("TestReadDependencyFromFileInterfaceWithoutPackage",
255 "net.sourceforge.plantumldependency.main.option.programminglanguage"),
256 JAVA_PROGRAMMING_LANGUAGE_CONTEXT2
257 .getParsedOrSeenDependency("net.sourceforge.plantumldependency.main.option.programminglanguage.TestReadDependencyFromFileInterfaceWithoutPackage"));
258 }
259
260
261
262
263
264
265 @Test
266 public void testGetParsedOrSeenDependencyWithNotExistingDependency() {
267 assertNull(JAVA_PROGRAMMING_LANGUAGE_CONTEXT2
268 .getParsedOrSeenDependency("net.sourceforge.test.GenericDependency"));
269 }
270
271
272
273
274
275
276 @Test
277 public void testGetPlantUMLClassesDiagram() {
278 assertEquals(PLANTUML_CLASSES_DIAGRAM_TEST2, JAVA_PROGRAMMING_LANGUAGE_CONTEXT2.getPlantUMLClassesDiagram());
279 }
280
281
282
283
284
285
286 @Test
287 public void testGetPlantUMLClassesDiagramWithNamePattern() {
288 assertEquals(
289 new PlantUMLClassesDiagramImpl(
290 new TreeSet < PlantUMLClassesDiagramElement >(
291 asList(new PlantUMLClassesDiagramElement[] {
292 new PlantUMLClassesDiagramClassElementImpl(
293 "net.sourceforge.plantumldependency.main.option.programminglanguage.TestReadDependencyFromFileInterfaceWithoutPackage"),
294 new PlantUMLClassesDiagramClassElementImpl(
295 "net.sourceforge.plantumldependency.main.option.programminglanguage.TestReadDependencyFromFileInterfaceWithoutPackage")})),
296 new TreeSet < PlantUMLClassesDiagramRelation >()),
297 JAVA_PROGRAMMING_LANGUAGE_CONTEXT7.getPlantUMLClassesDiagram());
298 }
299
300
301
302
303
304
305 @Test
306 public void testGetPlantUMLClassesDiagramWithPackageNamePattern() {
307 assertEquals(
308 new PlantUMLClassesDiagramImpl(
309 new TreeSet < PlantUMLClassesDiagramElement >(
310 asList(new PlantUMLClassesDiagramElement[] {new PlantUMLClassesDiagramClassElementImpl(
311 "net.sourceforge.plantumldependency.main.option.programminglanguage.TestReadDependencyFromFileInterfaceWithoutPackage")})),
312 new TreeSet < PlantUMLClassesDiagramRelation >()),
313 JAVA_PROGRAMMING_LANGUAGE_CONTEXT6.getPlantUMLClassesDiagram());
314 }
315
316
317
318
319
320
321 @Test
322 public void testGetPotentialJavaLangSeenDependencies() {
323 assertEquals(1, JAVA_PROGRAMMING_LANGUAGE_CONTEXT4.getPotentialJavaLangSeenDependencies().size());
324 }
325
326
327
328
329
330
331 @Test
332 public void testHasToDisplayWithExistingDisplay() {
333 assertTrue(JAVA_PROGRAMMING_LANGUAGE_CONTEXT2.hasToDisplay(ABSTRACT_CLASSES));
334 }
335
336
337
338
339
340
341 @Test
342 public void testRemoveAllPotentialJavaLangSeenDependencyAndChangePackageToJavaLang() {
343 final GenericDependency dependency = new GenericDependencyImpl(
344 "TestReadDependencyFromFileInterfaceWithoutPackage",
345 "net.sourceforge.plantumldependency.main.option.programminglanguage");
346 final JavaProgrammingLanguageContext javaProgrammingLanguageContext = new JavaProgrammingLanguageContext(
347 new TreeSet < GenericDependency >(asList(new GenericDependency[] {dependency,
348 new GenericDependencyImpl("GenericDependency", "net.sourceforge.plantumldependency.generic")})),
349 new TreeSet < GenericDependency >(asList(new GenericDependency[] {new GenericDependencyImpl(
350 "GenericDependency", "net.sourceforge.plantumldependency.generic")})),
351 new TreeSet < GenericDependency >(asList(new GenericDependency[] {dependency})), DISPLAY_TYPES_OPTIONS,
352 DEFAULT_DISPLAY_PACKAGE_NAME_OPTIONS_PATTERN, DEFAULT_DISPLAY_NAME_OPTIONS_PATTERN);
353 javaProgrammingLanguageContext.removeAllPotentialJavaLangSeenDependencyAndChangePackageToJavaLang();
354 assertEquals(2, javaProgrammingLanguageContext.getParsedAndSeenDependencies().size());
355 assertEquals(1, javaProgrammingLanguageContext.getParsedDependencies().size());
356 assertEquals(0, javaProgrammingLanguageContext.getPotentialJavaLangSeenDependencies().size());
357 assertNotNull(javaProgrammingLanguageContext
358 .getParsedOrSeenDependency("java.lang.TestReadDependencyFromFileInterfaceWithoutPackage"));
359 }
360
361
362
363
364
365
366 @Test
367 public void testRemovePotentialJavaLangSeenDependencyWithExistingDependency() {
368 final JavaProgrammingLanguageContext javaProgrammingLanguageContext = (JavaProgrammingLanguageContext) JAVA_PROGRAMMING_LANGUAGE_CONTEXT4
369 .deepClone();
370 javaProgrammingLanguageContext
371 .removePotentialJavaLangSeenDependency("net.sourceforge.plantumldependency.main.option.programminglanguage.TestReadDependencyFromFileInterfaceWithoutPackage");
372 assertEquals(2, javaProgrammingLanguageContext.getParsedAndSeenDependencies().size());
373 assertEquals(0, javaProgrammingLanguageContext.getPotentialJavaLangSeenDependencies().size());
374 }
375
376
377
378
379
380
381 @Test
382 public void testRemovePotentialJavaLangSeenDependencyWithNotExistingDependency() {
383 final JavaProgrammingLanguageContext javaProgrammingLanguageContext = (JavaProgrammingLanguageContext) JAVA_PROGRAMMING_LANGUAGE_CONTEXT4
384 .deepClone();
385 javaProgrammingLanguageContext
386 .removePotentialJavaLangSeenDependency("net.sourceforge.mazix.components.clone.DeepCloneable");
387 assertEquals(2, javaProgrammingLanguageContext.getParsedAndSeenDependencies().size());
388 assertEquals(1, javaProgrammingLanguageContext.getPotentialJavaLangSeenDependencies().size());
389 }
390
391
392 }