Chromium Code Reviews| 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 junit.framework.TestCase; | |
| 8 | |
| 9 import org.chromium.testing.local.LocalRobolectricTestRunner; | |
| 10 import org.junit.Assert; | |
| 11 import org.junit.Test; | |
| 12 import org.junit.runner.RunWith; | |
| 13 import org.robolectric.annotation.Config; | |
| 14 | |
| 15 import java.lang.annotation.Annotation; | |
| 16 import java.lang.annotation.Retention; | |
| 17 import java.lang.annotation.RetentionPolicy; | |
| 18 import java.lang.reflect.AnnotatedElement; | |
| 19 import java.lang.reflect.Method; | |
| 20 import java.util.List; | |
| 21 | |
| 22 /** Unit tests for SkipCheck. */ | |
| 23 @RunWith(LocalRobolectricTestRunner.class) | |
| 24 @Config(manifest = Config.NONE) | |
| 25 public class SkipCheckTest { | |
| 26 | |
| 27 private static class TestableSkipCheck extends SkipCheck { | |
| 28 public static <T extends Annotation> List<T> getAnnotationsForTesting( | |
| 29 AnnotatedElement element, Class<T> annotationClass) { | |
| 30 return getAnnotations(element, annotationClass); | |
| 31 } | |
| 32 | |
| 33 @Override | |
| 34 public boolean shouldSkip(TestCase t) { | |
| 35 return false; | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 @Retention(RetentionPolicy.RUNTIME) | |
| 40 private @interface TestAnnotation {} | |
| 41 | |
| 42 private class UnannotatedBaseClass { | |
| 43 public void unannotatedMethod() {} | |
| 44 @TestAnnotation public void annotatedMethod() {} | |
| 45 } | |
| 46 | |
| 47 @TestAnnotation | |
| 48 private class AnnotatedBaseClass { | |
| 49 public void unannotatedMethod() {} | |
| 50 @TestAnnotation public void annotatedMethod() {} | |
| 51 } | |
| 52 | |
| 53 private class ExtendsAnnotatedBaseClass extends AnnotatedBaseClass { | |
| 54 public void anotherUnannotatedMethod() {} | |
| 55 } | |
| 56 | |
| 57 @Test | |
| 58 public void getAnnotationsForClassNone() { | |
| 59 List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTe sting( | |
| 60 UnannotatedBaseClass.class, TestAnnotation.class); | |
| 61 Assert.assertTrue(annotations.isEmpty()); | |
|
newt (away)
2016/03/08 00:26:56
IMO, "assertEquals(0, annotations.size())" will pr
jbudorick
2016/03/08 01:49:26
hm, it does. switched here and below.
| |
| 62 } | |
| 63 | |
| 64 @Test | |
| 65 public void getAnnotationsForClassOnClass() { | |
| 66 List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTe sting( | |
| 67 AnnotatedBaseClass.class, TestAnnotation.class); | |
| 68 Assert.assertEquals(1, annotations.size()); | |
| 69 } | |
| 70 | |
| 71 @Test | |
| 72 public void getAnnotationsForClassOnSuperclass() { | |
| 73 List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTe sting( | |
| 74 ExtendsAnnotatedBaseClass.class, TestAnnotation.class); | |
| 75 Assert.assertEquals(1, annotations.size()); | |
| 76 } | |
| 77 | |
| 78 @Test | |
| 79 public void getAnnotationsForMethodNone() throws NoSuchMethodException { | |
| 80 Method testMethod = UnannotatedBaseClass.class.getMethod("unannotatedMet hod", | |
| 81 (Class[]) null); | |
| 82 List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTe sting( | |
| 83 testMethod, TestAnnotation.class); | |
| 84 Assert.assertTrue(annotations.isEmpty()); | |
| 85 } | |
| 86 | |
| 87 @Test | |
| 88 public void getAnnotationsForMethodOnMethod() throws NoSuchMethodException { | |
| 89 Method testMethod = UnannotatedBaseClass.class.getMethod("annotatedMetho d", | |
| 90 (Class[]) null); | |
| 91 List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTe sting( | |
| 92 testMethod, TestAnnotation.class); | |
| 93 Assert.assertEquals(1, annotations.size()); | |
| 94 } | |
| 95 | |
| 96 @Test | |
| 97 public void getAnnotationsForMethodOnClass() throws NoSuchMethodException { | |
| 98 Method testMethod = AnnotatedBaseClass.class.getMethod("unannotatedMetho d", | |
| 99 (Class[]) null); | |
| 100 List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTe sting( | |
| 101 testMethod, TestAnnotation.class); | |
| 102 Assert.assertEquals(1, annotations.size()); | |
| 103 } | |
| 104 | |
| 105 @Test | |
| 106 public void getAnnotationsForMethodOnSuperclass() throws NoSuchMethodExcepti on { | |
| 107 Method testMethod = ExtendsAnnotatedBaseClass.class.getMethod("unannotat edMethod", | |
| 108 (Class[]) null); | |
| 109 List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTe sting( | |
| 110 testMethod, TestAnnotation.class); | |
| 111 Assert.assertEquals(1, annotations.size()); | |
| 112 } | |
| 113 | |
| 114 @Test | |
| 115 public void getAnnotationsOverlapping() throws NoSuchMethodException { | |
| 116 Method testMethod = AnnotatedBaseClass.class.getMethod("annotatedMethod" , | |
| 117 (Class[]) null); | |
| 118 List<TestAnnotation> annotations = TestableSkipCheck.getAnnotationsForTe sting( | |
| 119 testMethod, TestAnnotation.class); | |
| 120 Assert.assertEquals(2, annotations.size()); | |
| 121 } | |
| 122 | |
| 123 } | |
| OLD | NEW |