forked from micw/php-java-bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestSetWriter.java
More file actions
63 lines (46 loc) · 1.42 KB
/
Copy pathTestSetWriter.java
File metadata and controls
63 lines (46 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package php.java.test;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import junit.framework.TestCase;
public class TestSetWriter extends TestCase {
public TestSetWriter(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public static class TestWriter extends Writer {
public void close() throws IOException {
throw new RuntimeException ("failed");
}
public void flush() throws IOException {
}
public void write(char[] cbuf, int off, int len) throws IOException {
assertTrue("3".equals(new String (cbuf, off, len)));
}
}
public static class TestReader extends Reader {
public void close() throws IOException {
throw new RuntimeException ("failed");
}
public int read(char[] cbuf, int off, int len) throws IOException {
return 0;
}
}
public void test() throws Exception {
ScriptEngineManager m = new ScriptEngineManager();
ScriptEngine e = m.getEngineByName("php");
ScriptContext c = e.getContext();
c.setWriter(new TestWriter());
c.setErrorWriter(new TestWriter());
c.setReader(new TestReader());
e.eval("<?php echo 1+2; ?>");
}
}