• 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

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
    /** The script engine. */
30
    private ScriptingEngine _scriptEngine;
31

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

147
    /**
148
     * Returns the value of the named property. Will return null if the property does not exist.
149
     *
150
     * @param propertyName
151
     *            the property name
152
     *
153
     * @return the object
154
     */
155
    public Object get(String propertyName) {
156
        return null;
1✔
157
    }
158

159
    /**
160
     * Returns the value of the index property. Will return null if the property does not exist.
161
     *
162
     * @param index
163
     *            the index
164
     *
165
     * @return the object
166
     */
167
    public Object get(int index) {
168
        return null;
×
169
    }
170

171
    /**
172
     * Sets the value of the named property. Will throw a runtime exception if the property does not exist or cannot
173
     * accept the specified value.
174
     *
175
     * @param propertyName
176
     *            the property name
177
     * @param value
178
     *            the value
179
     */
180
    public void set(String propertyName, Object value) {
181
        throw new RuntimeException("No such property: " + propertyName);
×
182
    }
183

184
    /**
185
     * Specifies the scripting engine to be used.
186
     *
187
     * @param scriptEngine
188
     *            the new script engine
189
     */
190
    public void setScriptEngine(ScriptingEngine scriptEngine) {
191
        _scriptEngine = scriptEngine;
1✔
192
    }
1✔
193

194
    /**
195
     * Gets the script engine.
196
     *
197
     * @return the script engine
198
     */
199
    public ScriptingEngine getScriptEngine() {
200
        return _scriptEngine != null ? _scriptEngine : NULL_SCRIPT_ENGINE;
1✔
201
    }
202

203
    /**
204
     * Gets the script engine.
205
     *
206
     * @param child
207
     *            the child
208
     *
209
     * @return the script engine
210
     */
211
    public ScriptingEngine getScriptEngine(ScriptableDelegate child) {
212
        return getScriptEngine().newScriptingEngine(child);
1✔
213
    }
214

215
    /**
216
     * Gets the delegates.
217
     *
218
     * @param elements
219
     *            the elements
220
     *
221
     * @return the delegates
222
     */
223
    protected ScriptableDelegate[] getDelegates(final HTMLElement[] elements) {
224
        ScriptableDelegate[] result = new ScriptableDelegate[elements.length];
1✔
225
        for (int i = 0; i < elements.length; i++) {
1✔
226
            result[i] = (ScriptableDelegate) elements[i].getScriptingHandler();
1✔
227
        }
228
        return result;
1✔
229
    }
230
}
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