Skip to content

Commit

Permalink
Changed switch to if-else to make Java 8 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
pvlasov committed Feb 19, 2025
1 parent 9f8be15 commit 9459d39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
mavenLocal()
}

dependencies {
Expand Down
32 changes: 14 additions & 18 deletions src/test/java/picocli/IAnnotatedElementProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,32 @@ public void testAnnotatedElementAccess() throws Exception {
org.junit.Assert.assertTrue(option.getter() instanceof IAnnotatedElementProvider);

String optionName = option.names()[0];
AnnotatedElement setterAnnotatedElement = ((IAnnotatedElementProvider) option.setter()).getAnnotatedElement();
AnnotatedElement getterAnnotatedElement = ((IAnnotatedElementProvider) option.getter()).getAnnotatedElement();
switch (optionName) {
case "-a":
case "-b":
AnnotatedElement setterAnnotatedElement = ((IAnnotatedElementProvider) option.setter()).getAnnotatedElement();
AnnotatedElement getterAnnotatedElement = ((IAnnotatedElementProvider) option.getter()).getAnnotatedElement();
if ("-a".equals(optionName) || "-b".equals(optionName)) {
org.junit.Assert.assertTrue(setterAnnotatedElement instanceof Field);
org.junit.Assert.assertTrue(getterAnnotatedElement instanceof Field);

Field setterField = (Field) setterAnnotatedElement;
org.junit.Assert.assertEquals(IAnnotatedElementProviderTestCommand.class, setterField.getDeclaringClass());
org.junit.Assert.assertEquals(optionName.substring(1), setterField.getName());
org.junit.Assert.assertEquals(IAnnotatedElementProviderTestCommand.class, setterField.getDeclaringClass());
org.junit.Assert.assertEquals(optionName.substring(1), setterField.getName());

Field getterField = (Field) getterAnnotatedElement;
org.junit.Assert.assertEquals(IAnnotatedElementProviderTestCommand.class, getterField.getDeclaringClass());
org.junit.Assert.assertEquals(optionName.substring(1), getterField.getName());
break;
case "-c":
org.junit.Assert.assertEquals(IAnnotatedElementProviderTestCommand.class, getterField.getDeclaringClass());
org.junit.Assert.assertEquals(optionName.substring(1), getterField.getName());
} else if ("-c".equals(optionName)) {
org.junit.Assert.assertTrue(setterAnnotatedElement instanceof Method);
org.junit.Assert.assertTrue(getterAnnotatedElement instanceof Method);

Method setterMethod = (Method) setterAnnotatedElement;
org.junit.Assert.assertEquals(IAnnotatedElementProviderTestCommand.class, setterMethod.getDeclaringClass());
org.junit.Assert.assertEquals("setC", setterMethod.getName());
org.junit.Assert.assertEquals(IAnnotatedElementProviderTestCommand.class, setterMethod.getDeclaringClass());
org.junit.Assert.assertEquals("setC", setterMethod.getName());

Method getterMethod = (Method) getterAnnotatedElement;
org.junit.Assert.assertEquals(IAnnotatedElementProviderTestCommand.class, getterMethod.getDeclaringClass());
org.junit.Assert.assertEquals("setC", getterMethod.getName());
break;
default:
org.junit.Assert.fail("Unexpected option: " + optionName);
org.junit.Assert.assertEquals(IAnnotatedElementProviderTestCommand.class, getterMethod.getDeclaringClass());
org.junit.Assert.assertEquals("setC", getterMethod.getName());
} else {
org.junit.Assert.fail("Unexpected option: " + optionName);
}
}
}
Expand Down

0 comments on commit 9459d39

Please sign in to comment.