• 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

68.18
/src/main/java/com/meterware/httpunit/scripting/ScriptableDelegate.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.httpunit.scripting;
21

22
import com.meterware.httpunit.HTMLElement;
23

24
/**
25
 * An interface for objects which will be accessible via scripting.
26
 **/
27
public abstract class ScriptableDelegate implements ScriptingHandler {
1✔
28

29
    private ScriptingEngine _scriptEngine;
30

31
    /**
32
     * a dummy ScriptingEngine implementation
33
     */
34
    public static final ScriptingEngine NULL_SCRIPT_ENGINE = new ScriptingEngine() {
1✔
35
        @Override
36
        public boolean supportsScriptLanguage(String language) {
37
            return false;
×
38
        }
39

40
        @Override
41
        public String runScript(String language, String script) {
42
            return "";
×
43
        }
44

45
        @Override
46
        public boolean doEventScript(String eventScript) {
47
            return true;
×
48
        }
49

50
        @Override
51
        public boolean doEvent(String eventScript) {
52
            return true;
×
53
        }
54

55
        @Override
56
        public boolean handleEvent(String eventName) {
57
            return true;
1✔
58
        }
59

60
        @Override
61
        public Object evaluateExpression(String urlString) {
62
            return null;
×
63
        }
64

65
        @Override
66
        public ScriptingEngine newScriptingEngine(ScriptableDelegate child) {
67
            return this;
×
68
        }
69

70
        @Override
71
        public void clearCaches() {
72
        }
×
73
    };
74

75
    @Override
76
    public boolean supportsScriptLanguage(String language) {
77
        return getScriptEngine().supportsScriptLanguage(language);
1✔
78
    }
79

80
    /**
81
     * handle the event that has the given script attached by compiling the eventScript as a function and executing it
82
     *
83
     * @param eventScript
84
     *            - the script to use
85
     *
86
     * @deprecated since 1.7 - use doEventScript instead
87
     */
88
    @Deprecated
89
    @Override
90
    public boolean doEvent(String eventScript) {
91
        return doEventScript(eventScript);
×
92
    }
93

94
    /**
95
     * Executes the specified scripted event.
96
     *
97
     * @param eventScript
98
     *            - the eventScript to execute
99
     *
100
     * @return true if the event has been handled.
101
     **/
102
    @Override
103
    public boolean doEventScript(String eventScript) {
104
        return eventScript.isEmpty() || getScriptEngine().doEventScript(eventScript);
1✔
105
    }
106

107
    /**
108
     * Executes the event Handler script for the specified event (such as onchange, onmousedown, onclick, onmouseup) if
109
     * it is defined.
110
     *
111
     * @param eventName
112
     *            the name of the event for which a handler should be run.
113
     *
114
     * @return whether the event with the given name was handled
115
     */
116
    @Override
117
    public boolean handleEvent(String eventName) {
118
        String eventScript = (String) get(eventName);
×
119
        return doEventScript(eventScript);
×
120
    }
121

122
    /**
123
     * Executes the specified script, returning any intended replacement text.
124
     *
125
     * @return the replacement text, which may be empty.
126
     **/
127
    @Override
128
    public String runScript(String language, String script) {
129
        return script.isEmpty() ? "" : getScriptEngine().runScript(language, script);
1✔
130
    }
131

132
    /**
133
     * Evaluates the specified javascript expression, returning its value.
134
     **/
135
    @Override
136
    public Object evaluateExpression(String urlString) {
137
        if (urlString.isEmpty()) {
1!
138
            return null;
×
139
        }
140
        return getScriptEngine().evaluateExpression(urlString);
1✔
141
    }
142

143
    @Override
144
    public void clearCaches() {
145
        getScriptEngine().clearCaches();
1✔
146
    }
1✔
147

148
    /**
149
     * Returns the value of the named property. Will return null if the property does not exist.
150
     **/
151
    public Object get(String propertyName) {
152
        return null;
1✔
153
    }
154

155
    /**
156
     * Returns the value of the index property. Will return null if the property does not exist.
157
     **/
158
    public Object get(int index) {
159
        return null;
×
160
    }
161

162
    /**
163
     * Sets the value of the named property. Will throw a runtime exception if the property does not exist or cannot
164
     * accept the specified value.
165
     **/
166
    public void set(String propertyName, Object value) {
167
        throw new RuntimeException("No such property: " + propertyName);
×
168
    }
169

170
    /**
171
     * Specifies the scripting engine to be used.
172
     */
173
    public void setScriptEngine(ScriptingEngine scriptEngine) {
174
        _scriptEngine = scriptEngine;
1✔
175
    }
1✔
176

177
    public ScriptingEngine getScriptEngine() {
178
        return _scriptEngine != null ? _scriptEngine : NULL_SCRIPT_ENGINE;
1✔
179
    }
180

181
    public ScriptingEngine getScriptEngine(ScriptableDelegate child) {
182
        return getScriptEngine().newScriptingEngine(child);
1✔
183
    }
184

185
    protected ScriptableDelegate[] getDelegates(final HTMLElement[] elements) {
186
        ScriptableDelegate[] result = new ScriptableDelegate[elements.length];
1✔
187
        for (int i = 0; i < elements.length; i++) {
1✔
188
            result[i] = (ScriptableDelegate) elements[i].getScriptingHandler();
1✔
189
        }
190
        return result;
1✔
191
    }
192
}
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