Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2011 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -66,7 +66,7 @@ class SimpleCommandLineArgsParser {
|
|||||||
String optionValue = null;
|
String optionValue = null;
|
||||||
if (optionText.contains("=")) {
|
if (optionText.contains("=")) {
|
||||||
optionName = optionText.substring(0, optionText.indexOf('='));
|
optionName = optionText.substring(0, optionText.indexOf('='));
|
||||||
optionValue = optionText.substring(optionText.indexOf('=')+1, optionText.length());
|
optionValue = optionText.substring(optionText.indexOf('=') + 1, optionText.length());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
optionName = optionText;
|
optionName = optionText;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -39,7 +39,7 @@ class JOptCommandLinePropertySourceTests {
|
|||||||
OptionSet options = parser.parse("--foo=bar");
|
OptionSet options = parser.parse("--foo=bar");
|
||||||
|
|
||||||
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
|
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
|
||||||
assertThat((String)ps.getProperty("foo")).isEqualTo("bar");
|
assertThat(ps.getProperty("foo")).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -50,7 +50,7 @@ class JOptCommandLinePropertySourceTests {
|
|||||||
|
|
||||||
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
|
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
|
||||||
assertThat(ps.containsProperty("foo")).isTrue();
|
assertThat(ps.containsProperty("foo")).isTrue();
|
||||||
assertThat((String)ps.getProperty("foo")).isEqualTo("");
|
assertThat(ps.getProperty("foo")).isEqualTo("");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -63,7 +63,7 @@ class JOptCommandLinePropertySourceTests {
|
|||||||
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
|
PropertySource<?> ps = new JOptCommandLinePropertySource(options);
|
||||||
assertThat(ps.containsProperty("o1")).isTrue();
|
assertThat(ps.containsProperty("o1")).isTrue();
|
||||||
assertThat(ps.containsProperty("o2")).isFalse();
|
assertThat(ps.containsProperty("o2")).isFalse();
|
||||||
assertThat((String)ps.getProperty("o1")).isEqualTo("");
|
assertThat(ps.getProperty("o1")).isEqualTo("");
|
||||||
assertThat(ps.getProperty("o2")).isNull();
|
assertThat(ps.getProperty("o2")).isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,8 +138,7 @@ class JOptCommandLinePropertySourceTests {
|
|||||||
assertThat(ps.containsProperty("o1")).isTrue();
|
assertThat(ps.containsProperty("o1")).isTrue();
|
||||||
assertThat(ps.containsProperty("o2")).isTrue();
|
assertThat(ps.containsProperty("o2")).isTrue();
|
||||||
|
|
||||||
String nonOptionArgs = (String)ps.getProperty("nonOptionArgs");
|
assertThat(ps.getProperty("nonOptionArgs")).isEqualTo("noa1,noa2");
|
||||||
assertThat(nonOptionArgs).isEqualTo("noa1,noa2");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -169,7 +168,8 @@ class JOptCommandLinePropertySourceTests {
|
|||||||
assertThat(ps.getProperty("o1")).isEqualTo("VAL_1");
|
assertThat(ps.getProperty("o1")).isEqualTo("VAL_1");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum OptionEnum {
|
public enum OptionEnum {
|
||||||
VAL_1;
|
VAL_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2019 the original author or authors.
|
* Copyright 2002-2020 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -33,8 +33,7 @@ class SimpleCommandLinePropertySourceTests {
|
|||||||
@Test
|
@Test
|
||||||
void withDefaultName() {
|
void withDefaultName() {
|
||||||
PropertySource<?> ps = new SimpleCommandLinePropertySource();
|
PropertySource<?> ps = new SimpleCommandLinePropertySource();
|
||||||
assertThat(ps.getName())
|
assertThat(ps.getName()).isEqualTo(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME);
|
||||||
.isEqualTo(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -52,8 +51,7 @@ class SimpleCommandLinePropertySourceTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withOptionArgsOnly() {
|
void withOptionArgsOnly() {
|
||||||
CommandLinePropertySource<?> ps =
|
CommandLinePropertySource<?> ps = new SimpleCommandLinePropertySource("--o1=v1", "--o2");
|
||||||
new SimpleCommandLinePropertySource("--o1=v1", "--o2");
|
|
||||||
assertThat(ps.containsProperty("o1")).isTrue();
|
assertThat(ps.containsProperty("o1")).isTrue();
|
||||||
assertThat(ps.containsProperty("o2")).isTrue();
|
assertThat(ps.containsProperty("o2")).isTrue();
|
||||||
assertThat(ps.containsProperty("o3")).isFalse();
|
assertThat(ps.containsProperty("o3")).isFalse();
|
||||||
@@ -77,8 +75,7 @@ class SimpleCommandLinePropertySourceTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withDefaultNonOptionArgsNameAndNonOptionArgsPresent() {
|
void withDefaultNonOptionArgsNameAndNonOptionArgsPresent() {
|
||||||
CommandLinePropertySource<?> ps =
|
CommandLinePropertySource<?> ps = new SimpleCommandLinePropertySource("--o1=v1", "noa1", "--o2", "noa2");
|
||||||
new SimpleCommandLinePropertySource("--o1=v1", "noa1", "--o2", "noa2");
|
|
||||||
|
|
||||||
assertThat(ps.containsProperty("nonOptionArgs")).isTrue();
|
assertThat(ps.containsProperty("nonOptionArgs")).isTrue();
|
||||||
assertThat(ps.containsProperty("o1")).isTrue();
|
assertThat(ps.containsProperty("o1")).isTrue();
|
||||||
@@ -90,8 +87,7 @@ class SimpleCommandLinePropertySourceTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void withCustomNonOptionArgsNameAndNoNonOptionArgsPresent() {
|
void withCustomNonOptionArgsNameAndNoNonOptionArgsPresent() {
|
||||||
CommandLinePropertySource<?> ps =
|
CommandLinePropertySource<?> ps = new SimpleCommandLinePropertySource("--o1=v1", "noa1", "--o2", "noa2");
|
||||||
new SimpleCommandLinePropertySource("--o1=v1", "noa1", "--o2", "noa2");
|
|
||||||
ps.setNonOptionArgsPropertyName("NOA");
|
ps.setNonOptionArgsPropertyName("NOA");
|
||||||
|
|
||||||
assertThat(ps.containsProperty("nonOptionArgs")).isFalse();
|
assertThat(ps.containsProperty("nonOptionArgs")).isFalse();
|
||||||
@@ -104,8 +100,7 @@ class SimpleCommandLinePropertySourceTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void covertNonOptionArgsToStringArrayAndList() {
|
void covertNonOptionArgsToStringArrayAndList() {
|
||||||
CommandLinePropertySource<?> ps =
|
CommandLinePropertySource<?> ps = new SimpleCommandLinePropertySource("--o1=v1", "noa1", "--o2", "noa2");
|
||||||
new SimpleCommandLinePropertySource("--o1=v1", "noa1", "--o2", "noa2");
|
|
||||||
StandardEnvironment env = new StandardEnvironment();
|
StandardEnvironment env = new StandardEnvironment();
|
||||||
env.getPropertySources().addFirst(ps);
|
env.getPropertySources().addFirst(ps);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user