@@ -9,26 +9,29 @@ public class AddFinalIntentionTest extends LightJavaCodeInsightFixtureTestCase {
99
1010 private static final String INTENTION_TEXT = "Add final modifier(添加final修饰)" ;
1111
12- private void doTest (String before , String after ) {
13- myFixture .configureByText ("Test.java" , before .replace ("<caret>" , "<caret>" )); // Ensure caret is processed
12+ private void doTest (final String before , final String after ) {
13+ assertTrue ("Test code must contain <caret>" , before .contains ("<caret>" ));
14+ myFixture .configureByText ("Test.java" , before );
1415 final IntentionAction intention = myFixture .findSingleIntention (INTENTION_TEXT );
1516 assertNotNull ("Intention '" + INTENTION_TEXT + "' not found" , intention );
1617 myFixture .launchAction (intention );
1718 myFixture .checkResult (after );
1819 }
1920
20- private void doTestNotAvailable (String content ) {
21- myFixture .configureByText ("Test.java" , content .replace ("<caret>" , "<caret>" )); // Ensure caret is processed
22- List <IntentionAction > intentions = myFixture .getAvailableIntentions ();
23- List <String > intentionTexts = intentions .stream ()
24- .map (IntentionAction ::getText )
25- .collect (Collectors .toList ());
21+ private void doTestNotAvailable (final String content ) {
22+ assertTrue ("Test code must contain <caret>" , content .contains ("<caret>" ));
23+ myFixture .configureByText ("Test.java" , content );
24+ final List <IntentionAction > intentions = myFixture .getAvailableIntentions ();
25+ final List <String > intentionTexts = intentions .stream ()
26+ .map (IntentionAction ::getText )
27+ .collect (Collectors .toList ());
2628 assertFalse ("Intention '" + INTENTION_TEXT + "' should not be available. Available: " + intentionTexts ,
2729 intentionTexts .contains (INTENTION_TEXT ));
2830 }
29-
30- private void doTestNoChange (String contentWithCaret ) {
31- String contentWithoutCaret = contentWithCaret .replace ("<caret>" , "" );
31+
32+ private void doTestNoChange (final String contentWithCaret ) {
33+ assertTrue ("Test code must contain <caret>" , contentWithCaret .contains ("<caret>" ));
34+ final String contentWithoutCaret = contentWithCaret .replace ("<caret>" , "" );
3235 myFixture .configureByText ("Test.java" , contentWithCaret );
3336 // Attempt to find the intention. It should be available.
3437 final IntentionAction intention = myFixture .findSingleIntention (INTENTION_TEXT );
@@ -38,23 +41,23 @@ private void doTestNoChange(String contentWithCaret) {
3841 }
3942
4043 public void testAddFinalToSingleParameter () {
41- String before = "class Test {\n " +
44+ final String before = "class Test {\n " +
4245 " void method(String pa<caret>ram1, int param2) {}\n " +
4346 "}" ;
44- String after = "class Test {\n " +
47+ final String after = "class Test {\n " +
4548 " void method(final String param1, int param2) {}\n " +
4649 "}" ;
4750 doTest (before , after );
4851 }
4952
5053 public void testAddFinalToSingleLocalVariable () {
51- String before = "class Test {\n " +
54+ final String before = "class Test {\n " +
5255 " void method() {\n " +
5356 " String l<caret>ocal1 = \" hello\" ;\n " +
5457 " int local2 = 10;\n " +
5558 " }\n " +
5659 "}" ;
57- String after = "class Test {\n " +
60+ final String after = "class Test {\n " +
5861 " void method() {\n " +
5962 " final String local1 = \" hello\" ;\n " +
6063 " int local2 = 10;\n " +
@@ -65,17 +68,17 @@ public void testAddFinalToSingleLocalVariable() {
6568
6669 public void testAddFinalToAllInMethodScope () {
6770 // Caret is removed in 'after' string by checkResult implicitly if not present.
68- String before = "class Test {\n " +
71+ final String before = "class Test {\n " +
6972 " void method(String param1, int param2) {\n " +
7073 " <caret>\n " +
7174 " String local1 = \" hello\" ;\n " +
7275 " int local2 = 10;\n " +
7376 " final String alreadyFinal = \" done\" ;\n " +
7477 " }\n " +
7578 "}" ;
76- String after = "class Test {\n " +
79+ final String after = "class Test {\n " +
7780 " void method(final String param1, final int param2) {\n " +
78- " \n " +
81+ " \n " +
7982 " final String local1 = \" hello\" ;\n " +
8083 " final int local2 = 10;\n " +
8184 " final String alreadyFinal = \" done\" ;\n " +
@@ -85,52 +88,52 @@ public void testAddFinalToAllInMethodScope() {
8588 }
8689
8790 public void testNotAvailableOnAlreadyFinalParameter () {
88- String content = "class Test {\n " +
91+ final String content = "class Test {\n " +
8992 " void method(final String pa<caret>ram1) {}\n " +
9093 "}" ;
9194 // As per current isAvailable & invoke logic, intention is available but makes no change.
9295 doTestNoChange (content );
9396 }
9497
9598 public void testNotAvailableOnAlreadyFinalLocalVariable () {
96- String content = "class Test {\n " +
99+ final String content = "class Test {\n " +
97100 " void method() {\n " +
98101 " final String lo<caret>cal1 = \" hello\" ;\n " +
99102 " }\n " +
100103 "}" ;
101104 // As per current isAvailable & invoke logic, intention is available but makes no change.
102105 doTestNoChange (content );
103106 }
104-
107+
105108 public void testNotAvailableOnClassDeclaration () {
106- String content = "class Te<caret>st {\n " +
109+ final String content = "class Te<caret>st {\n " +
107110 " void method(String param1) {}\n " +
108111 "}" ;
109112 doTestNotAvailable (content );
110113 }
111114
112115 public void testNotAvailableInImportStatement () {
113- String content = "import ja<caret>va.util.List;\n " +
116+ final String content = "import ja<caret>va.util.List;\n " +
114117 "class Test {\n " +
115118 " void method(String param1) {}\n " +
116119 "}" ;
117120 doTestNotAvailable (content );
118121 }
119-
122+
120123 public void testNotAvailableOnFieldName () {
121124 // The current isAvailable will make it available for fields.
122125 // The invoke method will make the field final.
123- String before = "class Test {\n " +
126+ final String before = "class Test {\n " +
124127 " String myFi<caret>eld = \" value\" ;\n " +
125128 "}" ;
126- String after = "class Test {\n " +
129+ final String after = "class Test {\n " +
127130 " final String myField = \" value\" ;\n " +
128131 "}" ;
129132 doTest (before , after );
130133 }
131134
132135 public void testNotAvailableOnAlreadyFinalFieldName () {
133- String content = "class Test {\n " +
136+ final String content = "class Test {\n " +
134137 " final String myFi<caret>eld = \" value\" ;\n " +
135138 "}" ;
136139 // Intention should be available (based on isAvailable) but do nothing (based on invoke)
@@ -141,6 +144,6 @@ public void testNotAvailableOnAlreadyFinalFieldName() {
141144 @ Override
142145 protected String getTestDataPath () {
143146 // Not using testData files for these tests, so path can be empty or root.
144- return "" ;
147+ return "" ;
145148 }
146149}
0 commit comments