OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.base.test.util; |
| 6 |
| 7 import android.text.TextUtils; |
| 8 |
| 9 import junit.framework.TestCase; |
| 10 |
| 11 import org.chromium.testing.local.LocalRobolectricTestRunner; |
| 12 import org.junit.Assert; |
| 13 import org.junit.Test; |
| 14 import org.junit.runner.RunWith; |
| 15 import org.robolectric.annotation.Config; |
| 16 |
| 17 /** Unit tests for RestrictionSkipCheck. */ |
| 18 @RunWith(LocalRobolectricTestRunner.class) |
| 19 @Config(manifest = Config.NONE) |
| 20 public class RestrictionSkipCheckTest { |
| 21 |
| 22 private static final String TEST_RESTRICTION_APPLIES = |
| 23 "org.chromium.base.test.util.RestrictionSkipCheckTest.TEST_RESTRICTI
ON_APPLIES"; |
| 24 private static final String TEST_RESTRICTION_DOES_NOT_APPLY = |
| 25 "org.chromium.base.test.util.RestrictionSkipCheckTest.TEST_RESTRICTI
ON_DOES_NOT_APPLY"; |
| 26 |
| 27 private static class TestRestrictionSkipCheck extends RestrictionSkipCheck { |
| 28 public TestRestrictionSkipCheck() { |
| 29 super(null); |
| 30 } |
| 31 protected boolean restrictionApplies(String restriction) { |
| 32 return TextUtils.equals(restriction, TEST_RESTRICTION_APPLIES); |
| 33 } |
| 34 } |
| 35 |
| 36 private static class UnannotatedBaseClass extends TestCase { |
| 37 public UnannotatedBaseClass(String name) { |
| 38 super(name); |
| 39 } |
| 40 @Restriction({TEST_RESTRICTION_APPLIES}) public void restrictedMethod()
{} |
| 41 @Restriction({TEST_RESTRICTION_DOES_NOT_APPLY}) public void unrestricted
Method() {} |
| 42 } |
| 43 |
| 44 @Restriction({TEST_RESTRICTION_APPLIES}) |
| 45 private static class RestrictedClass extends UnannotatedBaseClass { |
| 46 public RestrictedClass(String name) { |
| 47 super(name); |
| 48 } |
| 49 public void unannotatedMethod() {} |
| 50 } |
| 51 |
| 52 @Restriction({TEST_RESTRICTION_DOES_NOT_APPLY}) |
| 53 private static class UnrestrictedClass extends UnannotatedBaseClass { |
| 54 public UnrestrictedClass(String name) { |
| 55 super(name); |
| 56 } |
| 57 public void unannotatedMethod() {} |
| 58 } |
| 59 |
| 60 @Restriction({ |
| 61 TEST_RESTRICTION_APPLIES, |
| 62 TEST_RESTRICTION_DOES_NOT_APPLY}) |
| 63 private static class MultipleRestrictionsRestrictedClass extends Unannotated
BaseClass { |
| 64 public MultipleRestrictionsRestrictedClass(String name) { |
| 65 super(name); |
| 66 } |
| 67 public void unannotatedMethod() {} |
| 68 } |
| 69 |
| 70 private static class ExtendsRestrictedClass extends RestrictedClass { |
| 71 public ExtendsRestrictedClass(String name) { |
| 72 super(name); |
| 73 } |
| 74 public void unannotatedMethod() {} |
| 75 } |
| 76 |
| 77 private static class ExtendsUnrestrictedClass extends UnrestrictedClass { |
| 78 public ExtendsUnrestrictedClass(String name) { |
| 79 super(name); |
| 80 } |
| 81 public void unannotatedMethod() {} |
| 82 } |
| 83 |
| 84 @Test |
| 85 public void testMethodRestricted() { |
| 86 Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip( |
| 87 new UnannotatedBaseClass("restrictedMethod"))); |
| 88 } |
| 89 |
| 90 @Test |
| 91 public void testMethodUnrestricted() { |
| 92 Assert.assertFalse(new TestRestrictionSkipCheck().shouldSkip( |
| 93 new UnannotatedBaseClass("unrestrictedMethod"))); |
| 94 } |
| 95 |
| 96 @Test |
| 97 public void testClassRestricted() { |
| 98 Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip( |
| 99 new RestrictedClass("unannotatedMethod"))); |
| 100 } |
| 101 |
| 102 @Test |
| 103 public void testClassUnrestricted() { |
| 104 Assert.assertFalse(new TestRestrictionSkipCheck().shouldSkip( |
| 105 new UnrestrictedClass("unannotatedMethod"))); |
| 106 } |
| 107 |
| 108 @Test |
| 109 public void testMultipleRestrictionsClassRestricted() { |
| 110 Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip( |
| 111 new MultipleRestrictionsRestrictedClass("unannotatedMethod"))); |
| 112 } |
| 113 |
| 114 @Test |
| 115 public void testSuperclassRestricted() { |
| 116 Assert.assertTrue(new TestRestrictionSkipCheck().shouldSkip( |
| 117 new ExtendsRestrictedClass("unannotatedMethod"))); |
| 118 } |
| 119 |
| 120 @Test |
| 121 public void testSuperclassUnrestricted() { |
| 122 Assert.assertFalse(new TestRestrictionSkipCheck().shouldSkip( |
| 123 new ExtendsUnrestrictedClass("unannotatedMethod"))); |
| 124 } |
| 125 |
| 126 } |
| 127 |
OLD | NEW |