Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Unified Diff: components/policy/android/junit/src/org/chromium/policy/test/annotations/PoliciesTest.java

Issue 1387633002: Update instrumentation tests to use PreTestHooks for policies (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments, use a map instead of hacking PolicyData's equality Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/policy/android/javatests/src/org/chromium/policy/test/annotations/Policies.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/policy/android/junit/src/org/chromium/policy/test/annotations/PoliciesTest.java
diff --git a/components/policy/android/junit/src/org/chromium/policy/test/annotations/PoliciesTest.java b/components/policy/android/junit/src/org/chromium/policy/test/annotations/PoliciesTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..7bc08e44940a52287409e074914c7a8d7b0c5082
--- /dev/null
+++ b/components/policy/android/junit/src/org/chromium/policy/test/annotations/PoliciesTest.java
@@ -0,0 +1,94 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.policy.test.annotations;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.chromium.policy.test.PolicyData;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Unit tests for the {@link Policies} annotations
+ */
+@RunWith(BlockJUnit4ClassRunner.class)
+public class PoliciesTest {
+ @Test
+ public void testGetPolicies() throws NoSuchMethodException {
+ Method method;
+
+ // Simple element, one annotation, no parent
+ assertThat(Policies.getPolicies(SomeClass.class).keySet(), is(makeSet("Ni")));
+
+ // Simple element, removing an annotation just has no effect
+ assertThat(Policies.getPolicies(SomeClassThatRemoves.class).isEmpty(), is(true));
+
+ // Simple element, adds and removes the same element: We process additions, then removals.
+ assertThat(Policies.getPolicies(SomeConfusedClass.class).isEmpty(), is(true));
+
+ // Annotations are inherited
+ method = SomeClass.class.getDeclaredMethod("someMethodWithoutWord");
+ assertThat(Policies.getPolicies(method).keySet(), is(makeSet("Ni")));
+
+ // Annotations add up
+ method = SomeClass.class.getDeclaredMethod("someMethod");
+ assertThat(Policies.getPolicies(method).keySet(), is(makeSet("Ni", "Neee-wom")));
+
+ // Annotations from methods are not inherited
+ method = SomeDerivedClass.class.getDeclaredMethod("someMethod");
+ assertThat(Policies.getPolicies(method).keySet(), is(makeSet("Ni")));
+
+ // Annotations are properly deduped, we get the one closest to the examined element
+ method = SomeClass.class.getDeclaredMethod("someMethodThatDuplicates");
+ Map<String, PolicyData> policies = Policies.getPolicies(method);
+ assertThat(policies.size(), is(1));
+ assertThat(policies.get("Ni"), is(PolicyData.Str.class));
+
+ // Annotations can be removed
+ method = SomeClass.class.getDeclaredMethod("someMethodThatTilRecentlyHadNi");
+ assertThat(Policies.getPolicies(method).keySet(),
+ is(makeSet("Ekke Ekke Ekke Ekke Ptangya Zoooooooom Boing Ni")));
+ }
+
+ private Set<String> makeSet(String... keys) {
+ return new HashSet<String>(Arrays.asList(keys));
+ }
+
+ @Policies.Add(@Policies.Item(key = "Ni"))
+ private static class SomeClass {
+ @SuppressWarnings("unused")
+ void someMethodWithoutWord() {}
+
+ @Policies.Add(@Policies.Item(key = "Neee-wom"))
+ void someMethod() {}
+
+ @Policies.Add(@Policies.Item(key = "Ni", string = "Makes it string, not undefined."))
+ void someMethodThatDuplicates() {}
+
+ @Policies.Remove(@Policies.Item(key = "Ni"))
+ @Policies.Add(@Policies.Item(key = "Ekke Ekke Ekke Ekke Ptangya Zoooooooom Boing Ni"))
+ void someMethodThatTilRecentlyHadNi() {}
+ }
+
+ private static class SomeDerivedClass extends SomeClass {
+ @Override
+ void someMethod() {}
+ }
+
+ @Policies.Remove(@Policies.Item(key = "Ni"))
+ private static class SomeClassThatRemoves {}
+
+ @Policies.Add(@Policies.Item(key = "Ni"))
+ @Policies.Remove(@Policies.Item(key = "Ni"))
+ private static class SomeConfusedClass {}
+}
« no previous file with comments | « components/policy/android/javatests/src/org/chromium/policy/test/annotations/Policies.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698