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

hazendaz / httpunit / 755

14 Feb 2026 07:14PM UTC coverage: 80.526%. Remained the same
755

push

github

hazendaz
[ci] Fix badge

3213 of 4105 branches covered (78.27%)

Branch coverage included in aggregate %.

8245 of 10124 relevant lines covered (81.44%)

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
 * SPDX-License-Identifier: MIT
3
 * See LICENSE file for details.
4
 *
5
 * Copyright 2000-2026 Russell Gold
6
 * Copyright 2021-2000 hazendaz
7
 */
8
package com.meterware.servletunit;
9

10
import java.util.ArrayList;
11

12
/**
13
 * The Class FilterUrlMap.
14
 */
15
class FilterUrlMap {
1✔
16

17
    /** The url patterns. */
18
    private ArrayList _urlPatterns = new ArrayList<>();
1✔
19

20
    /** The filters. */
21
    private ArrayList _filters = new ArrayList<>();
1✔
22

23
    /**
24
     * Put.
25
     *
26
     * @param urlPattern
27
     *            the url pattern
28
     * @param metaData
29
     *            the meta data
30
     */
31
    void put(String urlPattern, FilterMetaData metaData) {
32
        _urlPatterns.add(UrlPatternMatcher.newPatternMatcher(urlPattern));
1✔
33
        _filters.add(metaData);
1✔
34
    }
1✔
35

36
    /**
37
     * Gets the matching filters.
38
     *
39
     * @param resourceName
40
     *            the resource name
41
     *
42
     * @return the matching filters
43
     */
44
    FilterMetaData[] getMatchingFilters(String resourceName) {
45
        ArrayList matches = new ArrayList<>();
1✔
46
        for (int i = 0; i < _urlPatterns.size(); i++) {
1✔
47
            UrlPatternMatcher urlPattern = (UrlPatternMatcher) _urlPatterns.get(i);
1✔
48
            if (urlPattern.matchesResourceName(resourceName)) {
1✔
49
                matches.add(_filters.get(i));
1✔
50
            }
51
        }
52
        return (FilterMetaData[]) matches.toArray(new FilterMetaData[matches.size()]);
1✔
53
    }
54

55
}
56

57
abstract class UrlPatternMatcher {
1✔
58

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

61
    static UrlPatternMatcher newPatternMatcher(String pattern) {
62
        for (UrlPatternMatcher _template : _templates) {
1✔
63
            UrlPatternMatcher matcher = _template.create(pattern);
1✔
64
            if (matcher != null) {
1✔
65
                return matcher;
1✔
66
            }
67
        }
68
        return new ExactUrlPatternMatcher(pattern);
1✔
69
    }
70

71
    /**
72
     * Returns a suitable pattern matcher if this class is compatible with the pattern. Will return null otherwise.
73
     */
74
    abstract UrlPatternMatcher create(String pattern);
75

76
    /**
77
     * Returns true if the specified resource matches this pattern.
78
     */
79
    abstract boolean matchesResourceName(String resourceName);
80
}
81

82
class ExactUrlPatternMatcher extends UrlPatternMatcher {
83
    private String _pattern;
84

85
    public ExactUrlPatternMatcher(String pattern) {
1✔
86
        _pattern = pattern;
1✔
87
    }
1✔
88

89
    @Override
90
    UrlPatternMatcher create(String pattern) {
91
        return new ExactUrlPatternMatcher(pattern);
×
92
    }
93

94
    @Override
95
    boolean matchesResourceName(String resourceName) {
96
        return _pattern.equals(resourceName);
1✔
97
    }
98
}
99

100
class ExtensionUrlPatternMatcher extends UrlPatternMatcher {
101
    private String _suffix;
102

103
    ExtensionUrlPatternMatcher() {
1✔
104
    }
1✔
105

106
    ExtensionUrlPatternMatcher(String suffix) {
1✔
107
        _suffix = suffix;
1✔
108
    }
1✔
109

110
    @Override
111
    UrlPatternMatcher create(String pattern) {
112
        return !pattern.startsWith("*.") ? null : new ExtensionUrlPatternMatcher(pattern.substring(1));
1✔
113
    }
114

115
    @Override
116
    boolean matchesResourceName(String resourceName) {
117
        return resourceName.endsWith(_suffix);
1✔
118
    }
119
}
120

121
class PathMappingUrlPatternMatcher extends UrlPatternMatcher {
122
    private String _exactPath;
123
    private String _prefix;
124

125
    PathMappingUrlPatternMatcher() {
1✔
126
    }
1✔
127

128
    PathMappingUrlPatternMatcher(String exactPath) {
1✔
129
        _exactPath = exactPath;
1✔
130
        _prefix = exactPath + '/';
1✔
131
    }
1✔
132

133
    @Override
134
    UrlPatternMatcher create(String pattern) {
135
        return !handlesPattern(pattern) ? null
1✔
136
                : new PathMappingUrlPatternMatcher(pattern.substring(0, pattern.length() - 2));
1✔
137
    }
138

139
    private boolean handlesPattern(String pattern) {
140
        return pattern.startsWith("/") && pattern.endsWith("/*");
1!
141
    }
142

143
    @Override
144
    boolean matchesResourceName(String resourceName) {
145
        return resourceName.startsWith(_prefix) || resourceName.equals(_exactPath);
1✔
146
    }
147
}
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