aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-04-18 15:30:49 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-04-19 09:42:11 +0000
commit7c3c3f1d1e985f1d2b61466c57f1d89b1114b0a7 (patch)
tree2ddc83c2ec446c17936ce11e37fe1b230c1e7b3b /src
parent9dc24effb614f3695c962c4e1d1012e9e2aeb453 (diff)
Add sanity unit test for options classes that are subclasses of other options classes.
-- MOS_MIGRATED_REVID=120125572
Diffstat (limited to 'src')
-rw-r--r--src/test/java/com/google/devtools/common/options/OptionsParserTest.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/common/options/OptionsParserTest.java b/src/test/java/com/google/devtools/common/options/OptionsParserTest.java
index 468139e056..96845a1ff6 100644
--- a/src/test/java/com/google/devtools/common/options/OptionsParserTest.java
+++ b/src/test/java/com/google/devtools/common/options/OptionsParserTest.java
@@ -86,6 +86,15 @@ public class OptionsParserTest {
public String baz;
}
+ /** Subclass of an options class. */
+ public static class ExampleBazSubclass extends ExampleBaz {
+
+ @Option(name = "baz_subclass",
+ category = "one",
+ defaultValue = "defaultBazSubclass")
+ public String bazSubclass;
+ }
+
/**
* Example with empty to null string converter
*/
@@ -146,6 +155,19 @@ public class OptionsParserTest {
}
@Test
+ public void parseWithOptionsInheritance() throws OptionsParsingException {
+ OptionsParser parser = newOptionsParser(ExampleBazSubclass.class);
+ parser.parse("--baz_subclass=cat", "--baz=dog");
+ ExampleBazSubclass subclassOptions = parser.getOptions(ExampleBazSubclass.class);
+ assertThat(subclassOptions.bazSubclass).isEqualTo("cat");
+ assertThat(subclassOptions.baz).isEqualTo("dog");
+ ExampleBaz options = parser.getOptions(ExampleBaz.class);
+ // This is a test showcasing the lack of functionality for retrieving parsed options at a
+ // superclass type class type. If there's a need for this functionality, we can add it later.
+ assertThat(options).isNull();
+ }
+
+ @Test
public void parserWithUnknownOption() {
OptionsParser parser = newOptionsParser(ExampleFoo.class, ExampleBaz.class);
try {