1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.surefire.junitcore;
20
21 import java.lang.annotation.Annotation;
22 import java.lang.reflect.Method;
23
24 import org.apache.maven.surefire.api.util.ReflectionUtils;
25 import org.apache.maven.surefire.common.junit4.JUnit4Reflector;
26 import org.junit.Ignore;
27 import org.junit.Test;
28 import org.junit.runner.Description;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertNotNull;
32 import static org.junit.Assert.assertNull;
33 import static org.junit.Assert.assertSame;
34
35
36
37
38
39
40 public class JUnit4Reflector481Test {
41 private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
42
43 @Test
44 public void testGetAnnotatedIgnore() {
45 final Method testSomething2 =
46 ReflectionUtils.getMethod(IgnoreWithDescription.class, "testSomething2", EMPTY_CLASS_ARRAY);
47 final Annotation[] annotations = testSomething2.getAnnotations();
48 Description desc =
49 Description.createTestDescription(IgnoreWithDescription.class, "testSomething2", annotations);
50 Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore(desc);
51 assertNotNull(annotatedIgnore);
52 assertEquals(
53 "testSomething2" + "(org.apache.maven.surefire.junitcore.JUnit4Reflector481Test$IgnoreWithDescription)",
54 desc.getDisplayName());
55 assertEquals(
56 "testSomething2" + "(org.apache.maven.surefire.junitcore.JUnit4Reflector481Test$IgnoreWithDescription)",
57 desc.toString());
58 assertEquals(
59 "org.apache.maven.surefire.junitcore.JUnit4Reflector481Test$IgnoreWithDescription",
60 desc.getClassName());
61 assertEquals("testSomething2", desc.getMethodName());
62 assertEquals(0, desc.getChildren().size());
63 assertEquals(2, desc.getAnnotations().size());
64 assertSame(annotatedIgnore, desc.getAnnotation(Ignore.class));
65 assertEquals(REASON, annotatedIgnore.value());
66 }
67
68 @Test
69 public void testGetAnnotatedIgnoreWithoutClass() {
70 final Method testSomething2 =
71 ReflectionUtils.getMethod(IgnoreWithDescription.class, "testSomething2", EMPTY_CLASS_ARRAY);
72 final Annotation[] annotations = testSomething2.getAnnotations();
73 Description desc = Description.createSuiteDescription("testSomething2", annotations);
74 Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore(desc);
75 assertNotNull(annotatedIgnore);
76 assertEquals("testSomething2", desc.getDisplayName());
77 assertEquals("testSomething2", desc.toString());
78 assertEquals("testSomething2", desc.getClassName());
79 assertNull(desc.getMethodName());
80 assertEquals(0, desc.getChildren().size());
81 assertEquals(2, desc.getAnnotations().size());
82 assertSame(annotatedIgnore, desc.getAnnotation(Ignore.class));
83 assertEquals(REASON, annotatedIgnore.value());
84 }
85
86 private static final String REASON = "Ignorance is bliss";
87
88
89
90
91 public static class IgnoreWithDescription {
92
93 @Test
94 @Ignore(REASON)
95 public void testSomething2() {}
96 }
97
98 @Test
99 public void testCreatePureDescription() {
100 Description description = JUnit4Reflector.createDescription("exception");
101 assertEquals("exception", description.getDisplayName());
102 assertEquals("exception", description.toString());
103 assertEquals(0, description.getChildren().size());
104 }
105
106 @Test
107 public void testCreateDescription() {
108 Ignore ignore = JUnit4Reflector.createIgnored("error");
109 Description description = JUnit4Reflector.createDescription("exception", ignore);
110 assertEquals("exception", description.getDisplayName());
111 assertEquals("exception", description.toString());
112 assertEquals("exception", description.getClassName());
113 assertEquals(0, description.getChildren().size());
114 Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore(description);
115 assertNotNull(annotatedIgnore);
116 assertEquals("error", annotatedIgnore.value());
117 }
118 }