Skip to content

Commit 2c5934d

Browse files
asashourphilwebb
authored andcommitted
Use 'switch' instead of 'if'
See gh-40985
1 parent 9ddb7b0 commit 2c5934d

File tree

2 files changed

+15
-31
lines changed

2 files changed

+15
-31
lines changed

buildSrc/src/main/java/org/springframework/boot/build/classpath/CheckClasspathForProhibitedDependencies.java

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -70,27 +70,18 @@ public void checkForProhibitedDependencies() {
7070

7171
private boolean prohibited(ModuleVersionIdentifier id) {
7272
String group = id.getGroup();
73-
if (group.equals("javax.batch")) {
74-
return false;
75-
}
76-
if (group.equals("javax.cache")) {
77-
return false;
78-
}
79-
if (group.equals("javax.money")) {
80-
return false;
81-
}
82-
if (group.equals("org.codehaus.groovy")) {
83-
return true;
84-
}
85-
if (group.equals("org.eclipse.jetty.toolchain")) {
86-
return true;
73+
switch (group) {
74+
case "javax.batch", "javax.cache", "javax.money" -> {
75+
return false;
76+
}
77+
case "commons-logging", "org.codehaus.groovy", "org.eclipse.jetty.toolchain",
78+
"org.apache.geronimo.specs" -> {
79+
return true;
80+
}
8781
}
8882
if (group.startsWith("javax")) {
8983
return true;
9084
}
91-
if (group.equals("commons-logging")) {
92-
return true;
93-
}
9485
if (group.equals("org.slf4j") && id.getName().equals("jcl-over-slf4j")) {
9586
return true;
9687
}
@@ -100,10 +91,7 @@ private boolean prohibited(ModuleVersionIdentifier id) {
10091
if (group.equals("org.apache.geronimo.specs")) {
10192
return true;
10293
}
103-
if (group.equals("com.sun.activation")) {
104-
return true;
105-
}
106-
return false;
94+
return group.equals("com.sun.activation");
10795
}
10896

10997
}

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtensionForkParameterizedTests.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -37,14 +37,10 @@ class ModifiedClassPathExtensionForkParameterizedTests {
3737
@ParameterizedTest
3838
@ValueSource(strings = { "one", "two", "three" })
3939
void testIsInvokedOnceForEachArgument(String argument) {
40-
if (argument.equals("one")) {
41-
assertThat(arguments).isEmpty();
42-
}
43-
else if (argument.equals("two")) {
44-
assertThat(arguments).doesNotContain("two", "three");
45-
}
46-
else if (argument.equals("three")) {
47-
assertThat(arguments).doesNotContain("three");
40+
switch (argument) {
41+
case "one" -> assertThat(arguments).isEmpty();
42+
case "two" -> assertThat(arguments).doesNotContain("two", "three");
43+
case "three" -> assertThat(arguments).doesNotContain("three");
4844
}
4945
arguments.add(argument);
5046
}

0 commit comments

Comments
 (0)