Skip to content

Commit cb7dfaf

Browse files
graememorganError Prone Team
authored and
Error Prone Team
committed
Remove the Side enum.
I think this removes one concern. :) I think I've retained the spirit of each test, but do shout if not. PiperOrigin-RevId: 748616665
1 parent d64c9ce commit cb7dfaf

File tree

1 file changed

+63
-67
lines changed

1 file changed

+63
-67
lines changed

core/src/test/java/com/google/errorprone/bugpatterns/StatementSwitchToExpressionSwitchTest.java

+63-67
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@
3232
/** Tests for {@link StatementSwitchToExpressionSwitch}. */
3333
@RunWith(JUnit4.class)
3434
public final class StatementSwitchToExpressionSwitchTest {
35-
private static final String SIDE =
36-
"""
37-
enum Side {
38-
OBVERSE,
39-
REVERSE
40-
};
41-
""";
4235
private static final String SUIT =
4336
"""
4437
enum Suit {
@@ -50,21 +43,16 @@ enum Suit {
5043
""";
5144
private final CompilationTestHelper helper =
5245
CompilationTestHelper.newInstance(StatementSwitchToExpressionSwitch.class, getClass())
53-
.addSourceLines("Suit.java", SUIT)
54-
.addSourceLines("Side.java", SIDE);
46+
.addSourceLines("Suit.java", SUIT);
5547
private final BugCheckerRefactoringTestHelper refactoringHelper =
5648
BugCheckerRefactoringTestHelper.newInstance(
5749
StatementSwitchToExpressionSwitch.class, getClass())
5850
.addInputLines("Suit.java", SUIT)
59-
.expectUnchanged()
60-
.addInputLines("Side.java", SIDE)
6151
.expectUnchanged();
6252
private final BugCheckerRefactoringTestHelper refactoringHelper2 =
6353
BugCheckerRefactoringTestHelper.newInstance(
6454
StatementSwitchToExpressionSwitch.class, getClass())
6555
.addInputLines("Suit.java", SUIT)
66-
.expectUnchanged()
67-
.addInputLines("Side.java", SIDE)
6856
.expectUnchanged();
6957

7058
@Test
@@ -74,19 +62,21 @@ public void switchByEnum_removesRedundantBreak_error() {
7462
"Test.java",
7563
"""
7664
class Test {
77-
public void foo(Side side) {
78-
switch (side) {
79-
case OBVERSE /* left comment */ /* and there is more: */ // to end of line
65+
public void foo(Suit suit) {
66+
switch (suit) {
67+
case HEART /* left comment */ /* and there is more: */ // to end of line
8068
:
8169
// Explanatory comment
82-
System.out.println("the front is called the");
70+
System.out.println("the best suit is called the");
8371
// Middle comment
84-
System.out.println("obverse");
72+
System.out.println("heart");
8573
// Break comment
8674
break;
8775
// End comment
88-
case REVERSE:
89-
System.out.println("reverse");
76+
case SPADE:
77+
case CLUB:
78+
case DIAMOND:
79+
System.out.println("non-heart");
9080
}
9181
}
9282
}
@@ -95,20 +85,20 @@ public void foo(Side side) {
9585
"Test.java",
9686
"""
9787
class Test {
98-
public void foo(Side side) {
99-
switch (side) {
100-
case OBVERSE -> {
88+
public void foo(Suit suit) {
89+
switch (suit) {
90+
case HEART -> {
10191
/* left comment */
10292
/* and there is more: */
10393
// to end of line
10494
// Explanatory comment
105-
System.out.println("the front is called the");
95+
System.out.println("the best suit is called the");
10696
// Middle comment
107-
System.out.println("obverse");
97+
System.out.println("heart");
10898
// Break comment
10999
// End comment
110100
}
111-
case REVERSE -> System.out.println("reverse");
101+
case SPADE, CLUB, DIAMOND -> System.out.println("non-heart");
112102
}
113103
}
114104
}
@@ -125,17 +115,19 @@ public void switchByEnumWithCompletionAnalysis_removesRedundantBreak_error() {
125115
"Test.java",
126116
"""
127117
class Test {
128-
public void foo(Side side) {
129-
switch (side) {
118+
public void foo(Suit suit) {
119+
switch (suit) {
130120
// Comment before first case
131-
case OBVERSE:
121+
case HEART:
132122
// Explanatory comment
133123
System.out.println("this block cannot complete normally");
134124
{
135125
throw new NullPointerException();
136126
}
137-
case REVERSE:
138-
System.out.println("reverse");
127+
case CLUB:
128+
case DIAMOND:
129+
case SPADE:
130+
System.out.println("non-heart");
139131
}
140132
}
141133
}
@@ -144,17 +136,17 @@ public void foo(Side side) {
144136
"Test.java",
145137
"""
146138
class Test {
147-
public void foo(Side side) {
148-
switch (side) {
149-
case OBVERSE -> {
139+
public void foo(Suit suit) {
140+
switch (suit) {
141+
case HEART -> {
150142
// Comment before first case
151143
// Explanatory comment
152144
System.out.println("this block cannot complete normally");
153145
{
154146
throw new NullPointerException();
155147
}
156148
}
157-
case REVERSE -> System.out.println("reverse");
149+
case CLUB, DIAMOND, SPADE -> System.out.println("non-heart");
158150
}
159151
}
160152
}
@@ -173,17 +165,19 @@ public void switchByEnumExhaustiveWithoutDefault_removesDefault_error() {
173165
"Test.java",
174166
"""
175167
class Test {
176-
public void foo(Side side) {
177-
switch (side) {
168+
public void foo(Suit suit) {
169+
switch (suit) {
178170
// Comment before first case
179-
case OBVERSE:
171+
case HEART:
180172
// Explanatory comment
181173
System.out.println("this block cannot complete normally");
182174
{
183175
throw new NullPointerException();
184176
}
185-
case REVERSE:
186-
System.out.println("reverse");
177+
case CLUB:
178+
case SPADE:
179+
case DIAMOND:
180+
System.out.println("non-heart");
187181
break;
188182
default:
189183
System.out.println("default");
@@ -195,17 +189,17 @@ public void foo(Side side) {
195189
"Test.java",
196190
"""
197191
class Test {
198-
public void foo(Side side) {
199-
switch (side) {
200-
case OBVERSE -> {
192+
public void foo(Suit suit) {
193+
switch (suit) {
194+
case HEART -> {
201195
// Comment before first case
202196
// Explanatory comment
203197
System.out.println("this block cannot complete normally");
204198
{
205199
throw new NullPointerException();
206200
}
207201
}
208-
case REVERSE -> System.out.println("reverse");
202+
case CLUB, SPADE, DIAMOND -> System.out.println("non-heart");
209203
default -> System.out.println("default");
210204
}
211205
}
@@ -220,17 +214,19 @@ public void foo(Side side) {
220214
"Test.java",
221215
"""
222216
class Test {
223-
public void foo(Side side) {
224-
switch (side) {
217+
public void foo(Suit suit) {
218+
switch (suit) {
225219
// Comment before first case
226-
case OBVERSE:
220+
case HEART:
227221
// Explanatory comment
228222
System.out.println("this block cannot complete normally");
229223
{
230224
throw new NullPointerException();
231225
}
232-
case REVERSE:
233-
System.out.println("reverse");
226+
case CLUB:
227+
case SPADE:
228+
case DIAMOND:
229+
System.out.println("non-heart");
234230
break;
235231
default:
236232
System.out.println("default");
@@ -242,17 +238,17 @@ public void foo(Side side) {
242238
"Test.java",
243239
"""
244240
class Test {
245-
public void foo(Side side) {
246-
switch (side) {
247-
case OBVERSE -> {
241+
public void foo(Suit suit) {
242+
switch (suit) {
243+
case HEART -> {
248244
// Comment before first case
249245
// Explanatory comment
250246
System.out.println("this block cannot complete normally");
251247
{
252248
throw new NullPointerException();
253249
}
254250
}
255-
case REVERSE -> System.out.println("reverse");
251+
case CLUB, SPADE, DIAMOND -> System.out.println("non-heart");
256252
}
257253
}
258254
}
@@ -1034,16 +1030,16 @@ private void bar() {}
10341030

10351031
@Test
10361032
public void switchByEnum_surroundingBracesCannotRemove_error() {
1037-
// Can't remove braces around OBVERSE because break statements are not a member of
1033+
// Can't remove braces around HEART because break statements are not a member of
10381034
// KINDS_CONVERTIBLE_WITHOUT_BRACES
10391035
refactoringHelper
10401036
.addInputLines(
10411037
"Test.java",
10421038
"""
10431039
class Test {
1044-
public void foo(Side side) {
1045-
switch (side) {
1046-
case OBVERSE:
1040+
public void foo(Suit suit) {
1041+
switch (suit) {
1042+
case HEART:
10471043
{
10481044
// The quick brown fox, jumps over the lazy dog, etc.
10491045
break;
@@ -1061,9 +1057,9 @@ public void foo(Side side) {
10611057
"Test.java",
10621058
"""
10631059
class Test {
1064-
public void foo(Side side) {
1065-
switch (side) {
1066-
case OBVERSE -> {
1060+
public void foo(Suit suit) {
1061+
switch (suit) {
1062+
case HEART -> {
10671063
// The quick brown fox, jumps over the lazy dog, etc.
10681064
}
10691065
default -> throw new RuntimeException("Invalid type.");
@@ -1078,16 +1074,16 @@ public void foo(Side side) {
10781074

10791075
@Test
10801076
public void switchByEnum_surroundingBracesEmpty_error() {
1081-
// Test handling of cases with surrounding braces that are empty. The braces around OBVERSE
1077+
// Test handling of cases with surrounding braces that are empty. The braces around HEART
10821078
// can be removed because throw is a member of KINDS_CONVERTIBLE_WITHOUT_BRACES.
10831079
refactoringHelper
10841080
.addInputLines(
10851081
"Test.java",
10861082
"""
10871083
class Test {
1088-
public void foo(Side side) {
1089-
switch (side) {
1090-
case OBVERSE:
1084+
public void foo(Suit suit) {
1085+
switch (suit) {
1086+
case HEART:
10911087
{
10921088
// The quick brown fox, jumps over the lazy dog, etc.
10931089
throw new RuntimeException("Invalid.");
@@ -1104,9 +1100,9 @@ public void foo(Side side) {
11041100
"Test.java",
11051101
"""
11061102
class Test {
1107-
public void foo(Side side) {
1108-
switch (side) {
1109-
case OBVERSE ->
1103+
public void foo(Suit suit) {
1104+
switch (suit) {
1105+
case HEART ->
11101106
// The quick brown fox, jumps over the lazy dog, etc.
11111107
throw new RuntimeException("Invalid.");
11121108
default -> {}

0 commit comments

Comments
 (0)