OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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; | |
6 | |
7 import static org.chromium.base.test.TestListInstrumentationRunListener.getAnnot ationJSON; | |
8 import static org.chromium.base.test.TestListInstrumentationRunListener.getTestM ethodJSON; | |
9 | |
10 import org.json.JSONObject; | |
11 import org.junit.Assert; | |
12 import org.junit.Test; | |
13 import org.junit.runner.Description; | |
14 import org.junit.runner.RunWith; | |
15 import org.robolectric.annotation.Config; | |
16 | |
17 import org.chromium.base.test.util.CommandLineFlags; | |
18 import org.chromium.testing.local.LocalRobolectricTestRunner; | |
19 | |
20 import java.util.Arrays; | |
21 | |
22 /** | |
23 * Robolectric test to ensure static methods in TestListInstrumentationRunListen er works properly. | |
24 */ | |
25 @RunWith(LocalRobolectricTestRunner.class) | |
26 @Config(manifest = Config.NONE) | |
27 public class TestListInstrumentationRunListenerTest { | |
28 @CommandLineFlags.Add("hello") | |
29 private static class ParentClass { | |
30 public void testA() {} | |
31 | |
32 @CommandLineFlags.Add("world") | |
33 public void testB() {} | |
34 } | |
35 | |
36 @CommandLineFlags.Remove("hello") | |
37 private static class ChildClass extends ParentClass { | |
38 } | |
39 | |
40 @Test | |
41 public void testGetTestMethodJSON_testA() throws Throwable { | |
42 Description desc = Description.createTestDescription( | |
43 ParentClass.class, "testA", | |
44 ParentClass.class.getMethod("testA").getAnnotations()); | |
45 JSONObject json = getTestMethodJSON(desc); | |
46 String expectedJsonString = | |
47 "{" | |
48 + "'method': 'testA'," | |
49 + "'annotations': {}" | |
50 + "}"; | |
51 expectedJsonString = expectedJsonString | |
52 .replaceAll("\\s", "") | |
53 .replaceAll("'", "\""); | |
54 Assert.assertEquals(expectedJsonString, json.toString()); | |
55 } | |
56 | |
57 @Test | |
58 public void testGetTestMethodJSON_testB() throws Throwable { | |
59 Description desc = Description.createTestDescription( | |
60 ParentClass.class, "testB", | |
61 ParentClass.class.getMethod("testB").getAnnotations()); | |
62 JSONObject json = getTestMethodJSON(desc); | |
63 String expectedJsonString = | |
64 "{" | |
65 + "'method': 'testB'," | |
66 + "'annotations': {" | |
67 + " 'Add': {" | |
68 + " 'value': ['world']" | |
69 + " }" | |
70 + " }" | |
71 + "}"; | |
72 expectedJsonString = expectedJsonString | |
73 .replaceAll("\\s", "") | |
74 .replaceAll("'", "\""); | |
75 Assert.assertEquals(expectedJsonString, json.toString()); | |
76 } | |
77 | |
78 | |
79 @Test | |
80 public void testGetTestMethodJSONForInheritedClass() throws Throwable { | |
81 Description desc = Description.createTestDescription( | |
82 ChildClass.class, "testB", | |
83 ChildClass.class.getMethod("testB").getAnnotations()); | |
84 JSONObject json = getTestMethodJSON(desc); | |
85 String expectedJsonString = | |
86 "{" | |
87 + "'method': 'testB'," | |
88 + "'annotations': {" | |
89 + " 'Add': {" | |
90 + " 'value': ['world']" | |
91 + " }" | |
92 + " }" | |
93 + "}"; | |
94 expectedJsonString = expectedJsonString | |
95 .replaceAll("\\s", "") | |
96 .replaceAll("'", "\""); | |
97 Assert.assertEquals(expectedJsonString, json.toString()); | |
98 } | |
99 | |
100 @Test | |
101 public void testGetAnnotationJSONForParentClass() throws Throwable { | |
102 JSONObject json = getAnnotationJSON(Arrays.asList(ParentClass.class.getA nnotations())); | |
103 String expectedJsonString = "{'Add':{'value':['hello']}}"; | |
104 expectedJsonString = expectedJsonString | |
105 .replaceAll("\\s", "") | |
106 .replaceAll("'", "\""); | |
107 System.out.println(json.toString()); | |
mikecase (-- gone --)
2017/07/21 18:47:13
probably dont want println in test
the real yoland
2017/07/21 18:58:08
Removed
| |
108 Assert.assertEquals(expectedJsonString, json.toString()); | |
109 } | |
110 | |
111 @Test | |
112 public void testGetAnnotationJSONForChildClass() throws Throwable { | |
113 JSONObject json = getAnnotationJSON(Arrays.asList(ChildClass.class.getAn notations())); | |
114 String expectedJsonString = "{'Add':{'value':['hello']},'Remove':{'value ':['hello']}}"; | |
115 expectedJsonString = expectedJsonString | |
116 .replaceAll("\\s", "") | |
117 .replaceAll("'", "\""); | |
118 Assert.assertEquals(expectedJsonString, json.toString()); | |
119 } | |
120 } | |
121 | |
OLD | NEW |