Skip to content

Commit 87b5052

Browse files
author
Fabrice-TIERCELIN
committed
Add more tests
1 parent d9917d5 commit 87b5052

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

samples/src/test/java/org/autorefactor/jdt/internal/ui/fix/samples_in/BreakRatherThanPassiveIterationsSample.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package org.autorefactor.jdt.internal.ui.fix.samples_in;
2727

2828
public class BreakRatherThanPassiveIterationsSample {
29+
private int[] innerArray = new int[10];
2930

3031
private int crazyInteger = 0;
3132

@@ -55,6 +56,19 @@ public String addBreakInForeachLoop(int[] array) {
5556
return isFound ? "The result has been found" : "The result has not been found";
5657
}
5758

59+
public String addBreakWithField() {
60+
boolean isFound = false;
61+
62+
for (int i : this.innerArray) {
63+
if (i == 42) {
64+
// Keep this comment
65+
isFound = true;
66+
}
67+
}
68+
69+
return isFound ? "The result has been found" : "The result has not been found";
70+
}
71+
5872
public String addBreakWithoutBlock(int[] array) {
5973
boolean isFound = false;
6074

samples/src/test/java/org/autorefactor/jdt/internal/ui/fix/samples_in/XORRatherThanDuplicateConditionsSample.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ public void replaceDuplicateConditionsWithExpressions(int i1, int i2, int i3, in
6868
boolean newBoolean4 = (i1 == i2) && (i3 < i4) || (i1 != i2) && (i4 <= i3);
6969
}
7070

71+
public void replaceDuplicateConditionsWithFields() {
72+
// Keep this comment
73+
boolean newBoolean1 = (staticField > 0) && (staticField < 100) || (staticField <= 0) && (staticField >= 100);
74+
boolean newBoolean2 = (staticField > 0) && (staticField < 100) || (staticField >= 100) && !(staticField > 0);
75+
}
76+
7177
public void doNotReplaceDuplicateConditionsWithMethods(List<String> myList) {
7278
boolean newBoolean1 = myList.remove("lorem") && !myList.remove("ipsum") || !myList.remove("lorem")
7379
&& myList.remove("ipsum");

samples/src/test/java/org/autorefactor/jdt/internal/ui/fix/samples_out/BreakRatherThanPassiveIterationsSample.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
package org.autorefactor.jdt.internal.ui.fix.samples_out;
2727

2828
public class BreakRatherThanPassiveIterationsSample {
29+
private int[] innerArray = new int[10];
2930

3031
private int crazyInteger = 0;
3132

@@ -57,6 +58,20 @@ public String addBreakInForeachLoop(int[] array) {
5758
return isFound ? "The result has been found" : "The result has not been found";
5859
}
5960

61+
public String addBreakWithField() {
62+
boolean isFound = false;
63+
64+
for (int i : this.innerArray) {
65+
if (i == 42) {
66+
// Keep this comment
67+
isFound = true;
68+
break;
69+
}
70+
}
71+
72+
return isFound ? "The result has been found" : "The result has not been found";
73+
}
74+
6075
public String addBreakWithoutBlock(int[] array) {
6176
boolean isFound = false;
6277

samples/src/test/java/org/autorefactor/jdt/internal/ui/fix/samples_out/XORRatherThanDuplicateConditionsSample.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ public void replaceDuplicateConditionsWithExpressions(int i1, int i2, int i3, in
6868
boolean newBoolean4 = (i1 == i2) == (i3 < i4);
6969
}
7070

71+
public void replaceDuplicateConditionsWithFields() {
72+
// Keep this comment
73+
boolean newBoolean1 = (staticField > 0) == (staticField < 100);
74+
boolean newBoolean2 = (staticField > 0) == (staticField < 100);
75+
}
76+
7177
public void doNotReplaceDuplicateConditionsWithMethods(List<String> myList) {
7278
boolean newBoolean1 = myList.remove("lorem") && !myList.remove("ipsum") || !myList.remove("lorem")
7379
&& myList.remove("ipsum");

0 commit comments

Comments
 (0)