• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / httpunit / 656

06 Dec 2025 09:11PM UTC coverage: 80.452% (+0.02%) from 80.435%
656

push

github

hazendaz
[maven-release-plugin] prepare for next development iteration

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10137 relevant lines covered (81.34%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.72
/src/main/java/com/meterware/servletunit/FilterUrlMap.java
1
/*
2
 * MIT License
3
 *
4
 * Copyright 2011-2025 Russell Gold
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
 *
11
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions
12
 * of the Software.
13
 *
14
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
15
 * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
17
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18
 * DEALINGS IN THE SOFTWARE.
19
 */
20
package com.meterware.servletunit;
21

22
import java.util.ArrayList;
23

24
/**
25
 * The Class FilterUrlMap.
26
 */
27
class FilterUrlMap {
1✔
28

29
    /** The url patterns. */
30
    private ArrayList _urlPatterns = new ArrayList<>();
1✔
31

32
    /** The filters. */
33
    private ArrayList _filters = new ArrayList<>();
1✔
34

35
    /**
36
     * Put.
37
     *
38
     * @param urlPattern
39
     *            the url pattern
40
     * @param metaData
41
     *            the meta data
42
     */
43
    void put(String urlPattern, FilterMetaData metaData) {
44
        _urlPatterns.add(UrlPatternMatcher.newPatternMatcher(urlPattern));
1✔
45
        _filters.add(metaData);
1✔
46
    }
1✔
47

48
    /**
49
     * Gets the matching filters.
50
     *
51
     * @param resourceName
52
     *            the resource name
53
     *
54
     * @return the matching filters
55
     */
56
    FilterMetaData[] getMatchingFilters(String resourceName) {
57
        ArrayList matches = new ArrayList<>();
1✔
58
        for (int i = 0; i < _urlPatterns.size(); i++) {
1✔
59
            UrlPatternMatcher urlPattern = (UrlPatternMatcher) _urlPatterns.get(i);
1✔
60
            if (urlPattern.matchesResourceName(resourceName)) {
1✔
61
                matches.add(_filters.get(i));
1✔
62
            }
63
        }
64
        return (FilterMetaData[]) matches.toArray(new FilterMetaData[matches.size()]);
1✔
65
    }
66

67
}
68

69
abstract class UrlPatternMatcher {
1✔
70

71
    static UrlPatternMatcher[] _templates = { new ExtensionUrlPatternMatcher(), new PathMappingUrlPatternMatcher() };
1✔
72

73
    static UrlPatternMatcher newPatternMatcher(String pattern) {
74
        for (UrlPatternMatcher _template : _templates) {
1✔
75
            UrlPatternMatcher matcher = _template.create(pattern);
1✔
76
            if (matcher != null) {
1✔
77
                return matcher;
1✔
78
            }
79
        }
80
        return new ExactUrlPatternMatcher(pattern);
1✔
81
    }
82

83
    /**
84
     * Returns a suitable pattern matcher if this class is compatible with the pattern. Will return null otherwise.
85
     */
86
    abstract UrlPatternMatcher create(String pattern);
87

88
    /**
89
     * Returns true if the specified resource matches this pattern.
90
     */
91
    abstract boolean matchesResourceName(String resourceName);
92
}
93

94
class ExactUrlPatternMatcher extends UrlPatternMatcher {
95
    private String _pattern;
96

97
    public ExactUrlPatternMatcher(String pattern) {
1✔
98
        _pattern = pattern;
1✔
99
    }
1✔
100

101
    @Override
102
    UrlPatternMatcher create(String pattern) {
103
        return new ExactUrlPatternMatcher(pattern);
×
104
    }
105

106
    @Override
107
    boolean matchesResourceName(String resourceName) {
108
        return _pattern.equals(resourceName);
1✔
109
    }
110
}
111

112
class ExtensionUrlPatternMatcher extends UrlPatternMatcher {
113
    private String _suffix;
114

115
    ExtensionUrlPatternMatcher() {
1✔
116
    }
1✔
117

118
    ExtensionUrlPatternMatcher(String suffix) {
1✔
119
        _suffix = suffix;
1✔
120
    }
1✔
121

122
    @Override
123
    UrlPatternMatcher create(String pattern) {
124
        return !pattern.startsWith("*.") ? null : new ExtensionUrlPatternMatcher(pattern.substring(1));
1✔
125
    }
126

127
    @Override
128
    boolean matchesResourceName(String resourceName) {
129
        return resourceName.endsWith(_suffix);
1✔
130
    }
131
}
132

133
class PathMappingUrlPatternMatcher extends UrlPatternMatcher {
134
    private String _exactPath;
135
    private String _prefix;
136

137
    PathMappingUrlPatternMatcher() {
1✔
138
    }
1✔
139

140
    PathMappingUrlPatternMatcher(String exactPath) {
1✔
141
        _exactPath = exactPath;
1✔
142
        _prefix = exactPath + '/';
1✔
143
    }
1✔
144

145
    @Override
146
    UrlPatternMatcher create(String pattern) {
147
        return !handlesPattern(pattern) ? null
1✔
148
                : new PathMappingUrlPatternMatcher(pattern.substring(0, pattern.length() - 2));
1✔
149
    }
150

151
    private boolean handlesPattern(String pattern) {
152
        return pattern.startsWith("/") && pattern.endsWith("/*");
1!
153
    }
154

155
    @Override
156
    boolean matchesResourceName(String resourceName) {
157
        return resourceName.startsWith(_prefix) || resourceName.equals(_exactPath);
1✔
158
    }
159
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc