Set default values differently
[rhynodge.git] / src / test / java / net / pterodactylus / util / envopt / ParserTest.java
index 5a729dc..5014b9d 100644 (file)
@@ -46,6 +46,13 @@ public class ParserTest {
                requiredTestOptions.getOptionOne();
        }
 
+       @Test
+       public void parserSetsDefaultValueIfValueIsMissing() {
+           Mockito.when(environment.getValue("foo")).thenReturn(Optional.empty());
+               DefaultTestOptions options = parser.parseEnvironment(DefaultTestOptions::new);
+               MatcherAssert.assertThat(options.optionOne, Matchers.is("something"));
+       }
+
        /**
         * Test class with options used by {@link Parser}.
         *
@@ -109,4 +116,16 @@ public class ParserTest {
 
        }
 
+       /**
+        * Test class with options used by {@link Parser}.
+        *
+        * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+        */
+       private static class DefaultTestOptions {
+
+               @Option(name = "foo", defaultValue = "something")
+               public final String optionOne = null;
+
+       }
+
 }