Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SingleGroupMatcher |
|
| 5.142857142857143;5,143 |
1 | package org.apache.maven.surefire.group.match; | |
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 | ||
22 | public class SingleGroupMatcher | |
23 | implements GroupMatcher | |
24 | { | |
25 | ||
26 | private String enabled; | |
27 | ||
28 | private Class<?> enabledClass; | |
29 | ||
30 | public SingleGroupMatcher( String enabled ) | |
31 | 34 | { |
32 | 34 | this.enabled = enabled.endsWith( ".class" ) ? enabled.substring( 0, enabled.length() - 6 ) : enabled; |
33 | 34 | } |
34 | ||
35 | @Override | |
36 | public int hashCode() | |
37 | { | |
38 | 26 | final int prime = 31; |
39 | 26 | int result = 1; |
40 | 26 | result = prime * result + ( ( enabled == null ) ? 0 : enabled.hashCode() ); |
41 | 26 | return result; |
42 | } | |
43 | ||
44 | @Override | |
45 | public boolean equals( Object obj ) | |
46 | { | |
47 | 0 | if ( this == obj ) |
48 | { | |
49 | 0 | return true; |
50 | } | |
51 | 0 | if ( obj == null ) |
52 | { | |
53 | 0 | return false; |
54 | } | |
55 | 0 | if ( getClass() != obj.getClass() ) |
56 | { | |
57 | 0 | return false; |
58 | } | |
59 | 0 | SingleGroupMatcher other = (SingleGroupMatcher) obj; |
60 | 0 | if ( enabled == null ) |
61 | { | |
62 | 0 | if ( other.enabled != null ) |
63 | { | |
64 | 0 | return false; |
65 | } | |
66 | } | |
67 | 0 | else if ( !enabled.equals( other.enabled ) ) |
68 | { | |
69 | 0 | return false; |
70 | } | |
71 | 0 | return true; |
72 | } | |
73 | ||
74 | @Override | |
75 | public String toString() | |
76 | { | |
77 | 0 | return "*" + enabled; |
78 | } | |
79 | ||
80 | public boolean enabled( Class<?>... cats ) | |
81 | { | |
82 | 37 | if ( cats != null ) |
83 | { | |
84 | 52 | for ( Class<?> cls : cats ) |
85 | { | |
86 | 45 | if ( enabledClass != null && enabledClass.isAssignableFrom( cls ) ) |
87 | { | |
88 | 1 | return true; |
89 | } | |
90 | ||
91 | 44 | String name = cls.getName(); |
92 | 44 | if ( name.endsWith( enabled ) ) |
93 | { | |
94 | 29 | return true; |
95 | } | |
96 | } | |
97 | } | |
98 | ||
99 | 7 | return false; |
100 | } | |
101 | ||
102 | public boolean enabled( String... cats ) | |
103 | { | |
104 | 0 | if ( enabled == null ) |
105 | { | |
106 | 0 | return true; |
107 | } | |
108 | ||
109 | 0 | for ( String cat : cats ) |
110 | { | |
111 | 0 | if ( cat == null || cat.trim().length() < 1 ) |
112 | { | |
113 | 0 | continue; |
114 | } | |
115 | ||
116 | // System.out.println( cat + ".endsWith(" + enabled + ")? " + ( cat.endsWith( enabled ) ) ); | |
117 | 0 | if ( cat.endsWith( enabled ) ) |
118 | { | |
119 | 0 | return true; |
120 | } | |
121 | } | |
122 | ||
123 | 0 | return false; |
124 | } | |
125 | ||
126 | public void loadGroupClasses( ClassLoader cloader ) | |
127 | { | |
128 | try | |
129 | { | |
130 | 1 | enabledClass = cloader.loadClass( enabled ); |
131 | } | |
132 | 0 | catch ( ClassNotFoundException e ) |
133 | { | |
134 | 0 | throw new RuntimeException( "Unable to load category: " + enabled, e ); |
135 | 1 | } |
136 | 1 | } |
137 | ||
138 | } |