1
+ /**
2
+ * Copyright (C) 2006-2021 INRIA and contributors
3
+ * Spoon - http://spoon.gforge.inria.fr/
4
+ *
5
+ * This software is governed by the CeCILL-C License under French law and
6
+ * abiding by the rules of distribution of free software. You can use, modify
7
+ * and/or redistribute the software under the terms of the CeCILL-C license as
8
+ * circulated by CEA, CNRS and INRIA at http://www.cecill.info.
9
+ *
10
+ * This program is distributed in the hope that it will be useful, but WITHOUT
11
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ * FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL-C License for more details.
13
+ *
14
+ * The fact that you are presently reading this means that you have had
15
+ * knowledge of the CeCILL-C license and that you accept its terms.
16
+ */
17
+ package spoon .reflect .visitor ;
18
+
19
+ import org .junit .jupiter .api .BeforeAll ;
20
+ import org .junit .jupiter .api .Test ;
21
+ import org .junit .jupiter .api .TestInstance ;
22
+ import spoon .Launcher ;
23
+ import spoon .reflect .declaration .CtType ;
24
+ import spoon .reflect .factory .Factory ;
25
+ import spoon .reflect .visitor .testclasses .simpleNestedClassWithFields ;
26
+
27
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
28
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
29
+
30
+ @ TestInstance (TestInstance .Lifecycle .PER_CLASS )
31
+ public class CacheBasedConflictFinderTest {
32
+
33
+ private CacheBasedConflictFinder cacheBasedConflictFinder ;
34
+
35
+ @ BeforeAll
36
+ public void setup () {
37
+ Factory factory = new Launcher ().getFactory ();
38
+ CtType <?> type = factory .Class ().get (simpleNestedClassWithFields .class );
39
+ this .cacheBasedConflictFinder = new CacheBasedConflictFinder (type );
40
+ }
41
+
42
+ @ Test
43
+ void testHasFieldConflictsWithConflictingField () {
44
+ // contract: hasFieldConflict returns true when a conflicting field name is passed as argument
45
+
46
+ Boolean shouldBeTrue = cacheBasedConflictFinder .hasFieldConflict ("testField" );
47
+ assertTrue (shouldBeTrue );
48
+ }
49
+
50
+ @ Test
51
+ void testHasFieldConflictsWithNonConflictingField () {
52
+ // contract: hasFieldConflict returns false when a non-conflicting field name is passed as argument
53
+
54
+ Boolean shouldBeFalse = cacheBasedConflictFinder .hasFieldConflict ("testField1" );
55
+ assertFalse (shouldBeFalse );
56
+ }
57
+
58
+ @ Test
59
+ void testHasNestedTypeConflictsWithConflictingArgument () {
60
+ // contract: hasNestedTypeConflict returns true when a argument is passed which is name of already existing
61
+ // nested types
62
+
63
+ Boolean shouldBeTrue = cacheBasedConflictFinder .hasNestedTypeConflict ("subClass" );
64
+ assertTrue (shouldBeTrue );
65
+ }
66
+
67
+ @ Test
68
+ void testHasNestedTypeConflictsWithNonConflictingArgument () {
69
+ // contract: hasNestedTypeConflict returns false when a argument is passed which isn't name of an already
70
+ // existing nested type
71
+
72
+ Boolean shouldBeFalse = cacheBasedConflictFinder .hasNestedTypeConflict ("subClass1" );
73
+ assertFalse (shouldBeFalse );
74
+ }
75
+ }
0 commit comments