aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/common/options/testing
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2017-08-23 21:40:49 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-08-24 13:59:07 +0200
commitedee4f2b02528f240cb342e9fe8c2ad14be0ada5 (patch)
tree12a1920eae7916ca0a0edf801d5a6981bd426507 /src/test/java/com/google/devtools/common/options/testing
parent1e2954d4b4094f5f3c1c5a4b5cf70240d0c82d52 (diff)
Check at compile time that all options are declared public, and are non-final and non-static.
Remove the now redundant check in the testing framework, as the cases being tested no longer compile. Keep tests that check the contents of the OptionsBase as a whole, however, as this is still not being tested at compile time. PiperOrigin-RevId: 166239209
Diffstat (limited to 'src/test/java/com/google/devtools/common/options/testing')
-rw-r--r--src/test/java/com/google/devtools/common/options/testing/OptionsTesterTest.java112
1 files changed, 9 insertions, 103 deletions
diff --git a/src/test/java/com/google/devtools/common/options/testing/OptionsTesterTest.java b/src/test/java/com/google/devtools/common/options/testing/OptionsTesterTest.java
index 6c350ee9d1..a791d149f3 100644
--- a/src/test/java/com/google/devtools/common/options/testing/OptionsTesterTest.java
+++ b/src/test/java/com/google/devtools/common/options/testing/OptionsTesterTest.java
@@ -51,21 +51,20 @@ public final class OptionsTesterTest {
/** Test options class for optionAnnotationCheck_PassesWhenAllFieldsAnnotated. */
public static final class OptionAnnotationCheckAllFieldsAnnotated extends BaseAllFieldsAnnotated {
@Option(
- name = "public declared field with annotation",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.NO_OP},
- defaultValue = "defaultFoo"
+ name = "public declared field with annotation",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.NO_OP},
+ defaultValue = "defaultFoo"
)
public String publicField;
@Option(
- name = "private declared field with annotation",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.NO_OP},
- defaultValue = "defaultFoo"
+ name = "other public declared field with annotation",
+ documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
+ effectTags = {OptionEffectTag.NO_OP},
+ defaultValue = "defaultFoo"
)
- @SuppressWarnings("unused")
- private String privateField;
+ public String publicField2;
}
@Test
@@ -137,12 +136,6 @@ public final class OptionsTesterTest {
private String privateUnAnnotatedField;
}
- @Test
- public void optionAccessCheck_PassesWhenAllFieldsPublicNotStaticNotFinal() throws Exception {
- new OptionsTester(OptionAccessCheckAllFieldsPublicNotStaticNotFinal.class)
- .testAllOptionFieldsPublic();
- }
-
/** Test options class for optionAccessCheck_PassesWhenAllFieldsPublicNotStaticNotFinal. */
public static class BaseAllFieldsPublicNotStaticNotFinal extends OptionsBase {
@Option(
@@ -166,11 +159,6 @@ public final class OptionsTesterTest {
public String annotatedField;
}
- @Test
- public void optionAccessCheck_IgnoresNonAnnotatedFields() throws Exception {
- new OptionsTester(OptionAccessCheckNonAnnotatedFields.class).testAllOptionFieldsPublic();
- }
-
/** Test options class for optionAccessCheck_IgnoresNonAnnotatedFields. */
public static class BaseNonAnnotatedFields extends OptionsBase {
protected static String parentClassUnAnnotatedStaticField;
@@ -186,88 +174,6 @@ public final class OptionsTesterTest {
protected String protectedDeclaredField;
}
- @Test
- public void optionAccessCheck_FailsForNonPublicFields() throws Exception {
- try {
- new OptionsTester(OptionAccessCheckNonPublicStaticField.class).testAllOptionFieldsPublic();
- } catch (AssertionError expected) {
- assertThat(expected).hasMessageThat().contains("protectedField");
- return;
- }
- fail("test is expected to have failed");
- }
-
- /** Test options class for optionAccessCheck_FailsForNonPublicFields. */
- public static class OptionAccessCheckNonPublicStaticField extends OptionsBase {
- @Option(
- name = "protected declared field with annotation",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.NO_OP},
- defaultValue = "defaultFoo"
- )
- protected String protectedField;
- }
-
- @Test
- public void optionAccessCheck_FailsForNonPublicFieldsInSuperclass() throws Exception {
- try {
- new OptionsTester(OptionAccessCheckInheritedUnAnnotatedField.class)
- .testAllOptionFieldsPublic();
- } catch (AssertionError expected) {
- assertThat(expected).hasMessageThat().contains("protectedField");
- return;
- }
- fail("test is expected to have failed");
- }
-
- /** Test options class for optionAccessCheck_FailsForNonPublicFieldsInSuperclass. */
- public static final class OptionAccessCheckInheritedUnAnnotatedField
- extends OptionAccessCheckNonPublicStaticField {}
-
- @Test
- public void optionAccessCheck_FailsForStaticFields() throws Exception {
- try {
- new OptionsTester(OptionAccessCheckPublicStaticField.class).testAllOptionFieldsPublic();
- } catch (AssertionError expected) {
- assertThat(expected).hasMessageThat().contains("staticField");
- return;
- }
- fail("test is expected to have failed");
- }
-
- /** Test options class for optionAccessCheck_FailsForStaticFields. */
- public static final class OptionAccessCheckPublicStaticField extends OptionsBase {
- @Option(
- name = "public static declared field with annotation",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.NO_OP},
- defaultValue = "defaultFoo"
- )
- public static String staticField;
- }
-
- @Test
- public void optionAccessCheck_FailsForFinalFields() throws Exception {
- try {
- new OptionsTester(OptionAccessCheckPublicFinalField.class).testAllOptionFieldsPublic();
- } catch (AssertionError expected) {
- assertThat(expected).hasMessageThat().contains("finalField");
- return;
- }
- fail("test is expected to have failed");
- }
-
- /** Test options class for optionAccessCheck_FailsForStaticFields. */
- public static final class OptionAccessCheckPublicFinalField extends OptionsBase {
- @Option(
- name = "public final declared field with annotation",
- documentationCategory = OptionDocumentationCategory.UNCATEGORIZED,
- effectTags = {OptionEffectTag.NO_OP},
- defaultValue = "defaultFoo"
- )
- public final String finalField = "";
- }
-
/** Test converter class for testing testAllDefaultValuesTestedBy. */
public static final class TestConverter implements Converter<String> {
@Override