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

hazendaz / httpunit / 636

05 Dec 2025 03:27AM UTC coverage: 80.509%. Remained the same
636

push

github

hazendaz
Cleanup more old since tags

you guessed it, at this point going to jautodoc the rest so the warnings on builds go away ;)

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8249 of 10132 relevant lines covered (81.42%)

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
class FilterUrlMap {
1✔
25

26
    private ArrayList _urlPatterns = new ArrayList<>();
1✔
27
    private ArrayList _filters = new ArrayList<>();
1✔
28

29
    void put(String urlPattern, FilterMetaData metaData) {
30
        _urlPatterns.add(UrlPatternMatcher.newPatternMatcher(urlPattern));
1✔
31
        _filters.add(metaData);
1✔
32
    }
1✔
33

34
    FilterMetaData[] getMatchingFilters(String resourceName) {
35
        ArrayList matches = new ArrayList<>();
1✔
36
        for (int i = 0; i < _urlPatterns.size(); i++) {
1✔
37
            UrlPatternMatcher urlPattern = (UrlPatternMatcher) _urlPatterns.get(i);
1✔
38
            if (urlPattern.matchesResourceName(resourceName)) {
1✔
39
                matches.add(_filters.get(i));
1✔
40
            }
41
        }
42
        return (FilterMetaData[]) matches.toArray(new FilterMetaData[matches.size()]);
1✔
43
    }
44

45
}
46

47
abstract class UrlPatternMatcher {
1✔
48

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

51
    static UrlPatternMatcher newPatternMatcher(String pattern) {
52
        for (UrlPatternMatcher _template : _templates) {
1✔
53
            UrlPatternMatcher matcher = _template.create(pattern);
1✔
54
            if (matcher != null) {
1✔
55
                return matcher;
1✔
56
            }
57
        }
58
        return new ExactUrlPatternMatcher(pattern);
1✔
59
    }
60

61
    /**
62
     * Returns a suitable pattern matcher if this class is compatible with the pattern. Will return null otherwise.
63
     */
64
    abstract UrlPatternMatcher create(String pattern);
65

66
    /**
67
     * Returns true if the specified resource matches this pattern.
68
     */
69
    abstract boolean matchesResourceName(String resourceName);
70
}
71

72
class ExactUrlPatternMatcher extends UrlPatternMatcher {
73
    private String _pattern;
74

75
    public ExactUrlPatternMatcher(String pattern) {
1✔
76
        _pattern = pattern;
1✔
77
    }
1✔
78

79
    @Override
80
    UrlPatternMatcher create(String pattern) {
81
        return new ExactUrlPatternMatcher(pattern);
×
82
    }
83

84
    @Override
85
    boolean matchesResourceName(String resourceName) {
86
        return _pattern.equals(resourceName);
1✔
87
    }
88
}
89

90
class ExtensionUrlPatternMatcher extends UrlPatternMatcher {
91
    private String _suffix;
92

93
    ExtensionUrlPatternMatcher() {
1✔
94
    }
1✔
95

96
    ExtensionUrlPatternMatcher(String suffix) {
1✔
97
        _suffix = suffix;
1✔
98
    }
1✔
99

100
    @Override
101
    UrlPatternMatcher create(String pattern) {
102
        return !pattern.startsWith("*.") ? null : new ExtensionUrlPatternMatcher(pattern.substring(1));
1✔
103
    }
104

105
    @Override
106
    boolean matchesResourceName(String resourceName) {
107
        return resourceName.endsWith(_suffix);
1✔
108
    }
109
}
110

111
class PathMappingUrlPatternMatcher extends UrlPatternMatcher {
112
    private String _exactPath;
113
    private String _prefix;
114

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

118
    PathMappingUrlPatternMatcher(String exactPath) {
1✔
119
        _exactPath = exactPath;
1✔
120
        _prefix = exactPath + '/';
1✔
121
    }
1✔
122

123
    @Override
124
    UrlPatternMatcher create(String pattern) {
125
        return !handlesPattern(pattern) ? null
1✔
126
                : new PathMappingUrlPatternMatcher(pattern.substring(0, pattern.length() - 2));
1✔
127
    }
128

129
    private boolean handlesPattern(String pattern) {
130
        return pattern.startsWith("/") && pattern.endsWith("/*");
1!
131
    }
132

133
    @Override
134
    boolean matchesResourceName(String resourceName) {
135
        return resourceName.startsWith(_prefix) || resourceName.equals(_exactPath);
1✔
136
    }
137
}
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