Use 'switch' instead of 'if'

See gh-40985
This commit is contained in:
Ahmed Ashour 2024-06-11 11:56:31 -07:00 committed by Phillip Webb
parent 9ddb7b0238
commit 2c5934dab2
2 changed files with 15 additions and 31 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -70,27 +70,18 @@ public class CheckClasspathForProhibitedDependencies extends DefaultTask {
private boolean prohibited(ModuleVersionIdentifier id) {
String group = id.getGroup();
if (group.equals("javax.batch")) {
return false;
}
if (group.equals("javax.cache")) {
return false;
}
if (group.equals("javax.money")) {
return false;
}
if (group.equals("org.codehaus.groovy")) {
return true;
}
if (group.equals("org.eclipse.jetty.toolchain")) {
return true;
switch (group) {
case "javax.batch", "javax.cache", "javax.money" -> {
return false;
}
case "commons-logging", "org.codehaus.groovy", "org.eclipse.jetty.toolchain",
"org.apache.geronimo.specs" -> {
return true;
}
}
if (group.startsWith("javax")) {
return true;
}
if (group.equals("commons-logging")) {
return true;
}
if (group.equals("org.slf4j") && id.getName().equals("jcl-over-slf4j")) {
return true;
}
@ -100,10 +91,7 @@ public class CheckClasspathForProhibitedDependencies extends DefaultTask {
if (group.equals("org.apache.geronimo.specs")) {
return true;
}
if (group.equals("com.sun.activation")) {
return true;
}
return false;
return group.equals("com.sun.activation");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -37,14 +37,10 @@ class ModifiedClassPathExtensionForkParameterizedTests {
@ParameterizedTest
@ValueSource(strings = { "one", "two", "three" })
void testIsInvokedOnceForEachArgument(String argument) {
if (argument.equals("one")) {
assertThat(arguments).isEmpty();
}
else if (argument.equals("two")) {
assertThat(arguments).doesNotContain("two", "three");
}
else if (argument.equals("three")) {
assertThat(arguments).doesNotContain("three");
switch (argument) {
case "one" -> assertThat(arguments).isEmpty();
case "two" -> assertThat(arguments).doesNotContain("two", "three");
case "three" -> assertThat(arguments).doesNotContain("three");
}
arguments.add(argument);
}