Polish contribution and SimpleCommandLineArgs-related code
Closes gh-34282
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 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.
|
||||
@@ -46,7 +46,7 @@ class SimpleCommandLineArgsParserTests {
|
||||
void withSingleOptionAndNoValue() {
|
||||
CommandLineArgs args = parser.parse("--o1");
|
||||
assertThat(args.containsOption("o1")).isTrue();
|
||||
assertThat(args.getOptionValues("o1")).isEqualTo(Collections.EMPTY_LIST);
|
||||
assertThat(args.getOptionValues("o1")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,6 +56,20 @@ class SimpleCommandLineArgsParserTests {
|
||||
assertThat(args.getOptionValues("o1")).containsExactly("v1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withRepeatedOptionAndSameValues() {
|
||||
CommandLineArgs args = parser.parse("--o1=v1", "--o1=v1", "--o1=v1");
|
||||
assertThat(args.containsOption("o1")).isTrue();
|
||||
assertThat(args.getOptionValues("o1")).containsExactly("v1", "v1", "v1");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withRepeatedOptionAndDifferentValues() {
|
||||
CommandLineArgs args = parser.parse("--o1=v1", "--o1=v2", "--o1=v3");
|
||||
assertThat(args.containsOption("o1")).isTrue();
|
||||
assertThat(args.getOptionValues("o1")).containsExactly("v1", "v2", "v3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void withMixOfOptionsHavingValueAndOptionsHavingNoValue() {
|
||||
CommandLineArgs args = parser.parse("--o1=v1", "--o2");
|
||||
@@ -95,17 +109,17 @@ class SimpleCommandLineArgsParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertOptionNamesIsUnmodifiable() {
|
||||
void optionNamesSetIsUnmodifiable() {
|
||||
CommandLineArgs args = new SimpleCommandLineArgsParser().parse();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
args.getOptionNames().add("bogus"));
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||
.isThrownBy(() -> args.getOptionNames().add("bogus"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void assertNonOptionArgsIsUnmodifiable() {
|
||||
void nonOptionArgsListIsUnmodifiable() {
|
||||
CommandLineArgs args = new SimpleCommandLineArgsParser().parse();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
args.getNonOptionArgs().add("foo"));
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||
.isThrownBy(() -> args.getNonOptionArgs().add("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
* Copyright 2002-2025 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.
|
||||
@@ -61,6 +61,15 @@ class SimpleCommandLinePropertySourceTests {
|
||||
assertThat(ps.getProperty("o3")).isNull();
|
||||
}
|
||||
|
||||
@Test // gh-34282
|
||||
void withRepeatedOptionArgs() {
|
||||
CommandLinePropertySource<?> ps = new SimpleCommandLinePropertySource("--o1=v1", "--o1=v2", "--o1=v3");
|
||||
assertThat(ps.containsProperty("o1")).isTrue();
|
||||
assertThat(ps.containsProperty("o2")).isFalse();
|
||||
assertThat(ps.getProperty("o1")).isEqualTo("v1,v2,v3");
|
||||
assertThat(ps.getProperty("o2")).isNull();
|
||||
}
|
||||
|
||||
@Test // gh-24464
|
||||
void withOptionalArg_andArgIsEmpty() {
|
||||
EnumerablePropertySource<?> ps = new SimpleCommandLinePropertySource("--foo=");
|
||||
|
||||
Reference in New Issue
Block a user