• 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

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

10
import com.meterware.httpunit.HTMLElement;
11

12
/**
13
 * An interface for objects which will be accessible via scripting.
14
 **/
15
public abstract class ScriptableDelegate implements ScriptingHandler {
1✔
16

17
    /** The script engine. */
18
    private ScriptingEngine _scriptEngine;
19

20
    /** a dummy ScriptingEngine implementation. */
21
    public static final ScriptingEngine NULL_SCRIPT_ENGINE = new ScriptingEngine() {
1✔
22
        @Override
23
        public boolean supportsScriptLanguage(String language) {
24
            return false;
×
25
        }
26

27
        @Override
28
        public String runScript(String language, String script) {
29
            return "";
×
30
        }
31

32
        @Override
33
        public boolean doEventScript(String eventScript) {
34
            return true;
×
35
        }
36

37
        @Override
38
        public boolean doEvent(String eventScript) {
39
            return true;
×
40
        }
41

42
        @Override
43
        public boolean handleEvent(String eventName) {
44
            return true;
1✔
45
        }
46

47
        @Override
48
        public Object evaluateExpression(String urlString) {
49
            return null;
×
50
        }
51

52
        @Override
53
        public ScriptingEngine newScriptingEngine(ScriptableDelegate child) {
54
            return this;
×
55
        }
56

57
        @Override
58
        public void clearCaches() {
59
        }
×
60
    };
61

62
    @Override
63
    public boolean supportsScriptLanguage(String language) {
64
        return getScriptEngine().supportsScriptLanguage(language);
1✔
65
    }
66

67
    /**
68
     * handle the event that has the given script attached by compiling the eventScript as a function and executing it
69
     *
70
     * @param eventScript
71
     *            - the script to use
72
     *
73
     * @deprecated since 1.7 - use doEventScript instead
74
     */
75
    @Deprecated
76
    @Override
77
    public boolean doEvent(String eventScript) {
78
        return doEventScript(eventScript);
×
79
    }
80

81
    /**
82
     * Executes the specified scripted event.
83
     *
84
     * @param eventScript
85
     *            - the eventScript to execute
86
     *
87
     * @return true if the event has been handled.
88
     **/
89
    @Override
90
    public boolean doEventScript(String eventScript) {
91
        return eventScript.isEmpty() || getScriptEngine().doEventScript(eventScript);
1✔
92
    }
93

94
    /**
95
     * Executes the event Handler script for the specified event (such as onchange, onmousedown, onclick, onmouseup) if
96
     * it is defined.
97
     *
98
     * @param eventName
99
     *            the name of the event for which a handler should be run.
100
     *
101
     * @return whether the event with the given name was handled
102
     */
103
    @Override
104
    public boolean handleEvent(String eventName) {
105
        String eventScript = (String) get(eventName);
×
106
        return doEventScript(eventScript);
×
107
    }
108

109
    /**
110
     * Executes the specified script, returning any intended replacement text.
111
     *
112
     * @return the replacement text, which may be empty.
113
     **/
114
    @Override
115
    public String runScript(String language, String script) {
116
        return script.isEmpty() ? "" : getScriptEngine().runScript(language, script);
1✔
117
    }
118

119
    /**
120
     * Evaluates the specified javascript expression, returning its value.
121
     **/
122
    @Override
123
    public Object evaluateExpression(String urlString) {
124
        if (urlString.isEmpty()) {
1!
125
            return null;
×
126
        }
127
        return getScriptEngine().evaluateExpression(urlString);
1✔
128
    }
129

130
    @Override
131
    public void clearCaches() {
132
        getScriptEngine().clearCaches();
1✔
133
    }
1✔
134

135
    /**
136
     * Returns the value of the named property. Will return null if the property does not exist.
137
     *
138
     * @param propertyName
139
     *            the property name
140
     *
141
     * @return the object
142
     */
143
    public Object get(String propertyName) {
144
        return null;
1✔
145
    }
146

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

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

172
    /**
173
     * Specifies the scripting engine to be used.
174
     *
175
     * @param scriptEngine
176
     *            the new script engine
177
     */
178
    public void setScriptEngine(ScriptingEngine scriptEngine) {
179
        _scriptEngine = scriptEngine;
1✔
180
    }
1✔
181

182
    /**
183
     * Gets the script engine.
184
     *
185
     * @return the script engine
186
     */
187
    public ScriptingEngine getScriptEngine() {
188
        return _scriptEngine != null ? _scriptEngine : NULL_SCRIPT_ENGINE;
1✔
189
    }
190

191
    /**
192
     * Gets the script engine.
193
     *
194
     * @param child
195
     *            the child
196
     *
197
     * @return the script engine
198
     */
199
    public ScriptingEngine getScriptEngine(ScriptableDelegate child) {
200
        return getScriptEngine().newScriptingEngine(child);
1✔
201
    }
202

203
    /**
204
     * Gets the delegates.
205
     *
206
     * @param elements
207
     *            the elements
208
     *
209
     * @return the delegates
210
     */
211
    protected ScriptableDelegate[] getDelegates(final HTMLElement[] elements) {
212
        ScriptableDelegate[] result = new ScriptableDelegate[elements.length];
1✔
213
        for (int i = 0; i < elements.length; i++) {
1✔
214
            result[i] = (ScriptableDelegate) elements[i].getScriptingHandler();
1✔
215
        }
216
        return result;
1✔
217
    }
218
}
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