View Javadoc
1   package org.apache.maven.surefire.common.junit48;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.surefire.testset.ResolvedTest;
23  import org.junit.runner.Description;
24  import org.junit.runner.manipulation.Filter;
25  
26  final class RequestedTest
27      extends Filter
28  {
29      private static final String CLASS_FILE_EXTENSION = ".class";
30  
31      private final ResolvedTest test;
32  
33      RequestedTest( ResolvedTest test )
34      {
35          this.test = test;
36      }
37  
38      @Override
39      public boolean shouldRun( Description description )
40      {
41          Class<?> realTestClass = description.getTestClass();
42          String methodName = description.getMethodName();
43          return realTestClass == null && methodName == null || test.shouldRun( classFile( realTestClass ), methodName );
44      }
45  
46      @Override
47      public String describe()
48      {
49          final String classPattern = test.getTestClassPattern();
50          final String methodPattern = test.getTestMethodPattern();
51          String description = classPattern == null ? "" : classPattern;
52          if ( methodPattern != null )
53          {
54              description += "#" + methodPattern;
55          }
56          return description.length() == 0 ? "*" : description;
57      }
58  
59      @Override
60      public boolean equals( Object o )
61      {
62          return this == o || o != null && getClass() == o.getClass() && test.equals( ( (RequestedTest) o ).test );
63      }
64  
65      @Override
66      public int hashCode()
67      {
68          return test.hashCode();
69      }
70  
71      private String classFile( Class<?> realTestClass )
72      {
73          return realTestClass.getName().replace( '.', '/' ) + CLASS_FILE_EXTENSION;
74      }
75  }