1 package org.apache.maven.surefire.junitcore;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.lang.annotation.Annotation;
23 import java.lang.reflect.Method;
24 import org.apache.maven.surefire.common.junit4.JUnit4Reflector;
25 import org.apache.maven.surefire.util.ReflectionUtils;
26
27 import org.junit.Ignore;
28 import org.junit.Test;
29 import org.junit.runner.Description;
30
31 import static org.junit.Assert.*;
32
33
34
35
36
37
38 public class JUnit4Reflector481Test
39 {
40 private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
41
42 @Test
43 public void testGetAnnotatedIgnore()
44 {
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( "testSomething2"
56 + "(org.apache.maven.surefire.junitcore.JUnit4Reflector481Test$IgnoreWithDescription)",
57 desc.toString() );
58 assertEquals( "org.apache.maven.surefire.junitcore.JUnit4Reflector481Test$IgnoreWithDescription",
59 desc.getClassName() );
60 assertEquals( "testSomething2", desc.getMethodName() );
61 assertEquals( 0, desc.getChildren().size() );
62 assertEquals( 2, desc.getAnnotations().size() );
63 assertSame( annotatedIgnore, desc.getAnnotation( Ignore.class ) );
64 assertEquals( reason, annotatedIgnore.value() );
65 }
66
67 @Test
68 public void testGetAnnotatedIgnoreWithoutClass()
69 {
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 public static class IgnoreWithDescription
89 {
90
91 @Test
92 @Ignore( reason )
93 public void testSomething2()
94 {
95 }
96 }
97
98 @Test
99 public void testCreatePureDescription()
100 {
101 Description description = JUnit4Reflector.createDescription( "exception" );
102 assertEquals( "exception", description.getDisplayName() );
103 assertEquals( "exception", description.toString() );
104 assertEquals( 0, description.getChildren().size() );
105 }
106
107 @Test
108 public void testCreateDescription()
109 {
110 Ignore ignore = JUnit4Reflector.createIgnored( "error" );
111 Description description = JUnit4Reflector.createDescription( "exception", ignore );
112 assertEquals( "exception", description.getDisplayName() );
113 assertEquals( "exception", description.toString() );
114 assertEquals( "exception", description.getClassName() );
115 assertEquals( 0, description.getChildren().size() );
116 Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore( description );
117 assertNotNull( annotatedIgnore );
118 assertEquals( "error", annotatedIgnore.value() );
119 }
120 }