View Javadoc
1   package org.apache.maven.surefire.common.junit4;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import junit.framework.TestCase;
22  import org.junit.Ignore;
23  import org.junit.Test;
24  import org.junit.runner.Description;
25  
26  /**
27   * @author Kristian Rosenvold
28   */
29  public class JUnit4Reflector40Test
30      extends TestCase
31  {
32      public void testGetAnnotatedIgnore()
33      {
34          Description desc = Description.createTestDescription( IgnoreWithDescription.class, "testSomething2" );
35          Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore( desc );
36          assertNull( annotatedIgnore );
37      }
38  
39      private static final String reason = "Ignorance is bliss";
40  
41      public static class IgnoreWithDescription
42      {
43  
44          @Test
45          @Ignore( reason )
46          public void testSomething2()
47          {
48          }
49      }
50  
51      public void testCreateIgnored()
52      {
53          Ignore ignore = JUnit4Reflector.createIgnored( "error" );
54          assertNotNull( ignore );
55          assertNotNull( ignore.value() );
56          assertEquals( "error", ignore.value() );
57      }
58  
59      public void testCreateDescription()
60      {
61          Ignore ignore = JUnit4Reflector.createIgnored( "error" );
62          Description description = JUnit4Reflector.createDescription( "exception", ignore );
63          assertEquals( "exception", description.getDisplayName() );
64          assertEquals( "exception", description.toString() );
65          assertEquals( 0, description.getChildren().size() );
66          // JUnit 4 description does not get annotations
67          Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore( description );
68          assertNull( annotatedIgnore );
69      }
70  
71      public void testCreatePureDescription()
72      {
73          Description description = JUnit4Reflector.createDescription( "exception" );
74          assertEquals( "exception", description.getDisplayName() );
75          assertEquals( "exception", description.toString() );
76          assertEquals( 0, description.getChildren().size() );
77      }
78  }
79  
80