Skip to content

Commit 78c4b2d

Browse files
committed
[test] rewrite SSLSocketTest to use helper
1 parent e377b8a commit 78c4b2d

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

src/test/java/org/jruby/ext/openssl/SSLSocketTest.java

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,32 @@
11
package org.jruby.ext.openssl;
22

3-
import java.io.IOException;
4-
import java.io.ByteArrayOutputStream;
5-
import java.io.InputStream;
63
import java.nio.ByteBuffer;
7-
import java.nio.charset.StandardCharsets;
84

9-
import org.jruby.Ruby;
105
import org.jruby.RubyArray;
116
import org.jruby.RubyFixnum;
127
import org.jruby.RubyInteger;
138
import org.jruby.RubyString;
149
import org.jruby.exceptions.RaiseException;
15-
import org.jruby.runtime.ThreadContext;
1610
import org.jruby.runtime.builtin.IRubyObject;
1711

1812
import org.junit.After;
1913
import org.junit.Before;
2014
import org.junit.Test;
2115
import static org.junit.Assert.*;
2216

23-
public class SSLSocketTest {
24-
25-
private Ruby runtime;
17+
public class SSLSocketTest extends OpenSSLHelper {
2618

2719
/** Loads the ssl_pair.rb script that creates a connected SSL socket pair. */
2820
private String start_ssl_server_rb() { return readResource("/start_ssl_server.rb"); }
2921

3022
@Before
31-
public void setUp() {
32-
runtime = Ruby.newInstance();
33-
// prepend lib/ so openssl.rb + jopenssl/ are loaded instead of the ones bundled in jruby-stdlib
34-
String libDir = new java.io.File("lib").getAbsolutePath();
35-
runtime.evalScriptlet("$LOAD_PATH.unshift '" + libDir + "'");
36-
runtime.evalScriptlet("require 'openssl'");
23+
public void setUp() throws Exception {
24+
setUpRuntime();
3725
}
3826

3927
@After
4028
public void tearDown() {
41-
if (runtime != null) {
42-
runtime.tearDown(false);
43-
runtime = null;
44-
}
29+
tearDownRuntime();
4530
}
4631

4732
/**
@@ -178,28 +163,10 @@ public void syswriteNonblockNetWriteDataConsistency() {
178163
}
179164
}
180165

181-
private ThreadContext currentContext() {
182-
return runtime.getCurrentContext();
183-
}
184-
185166
private void closeQuietly(final RubyArray sslPair) {
186167
for (int i = 0; i < sslPair.getLength(); i++) {
187168
try { sslPair.entry(i).callMethod(currentContext(), "close"); }
188169
catch (RaiseException e) { /* already closed */ }
189170
}
190171
}
191-
192-
static String readResource(final String resource) {
193-
int n;
194-
try (InputStream in = SSLSocketTest.class.getResourceAsStream(resource)) {
195-
if (in == null) throw new IllegalArgumentException(resource + " not found on classpath");
196-
197-
ByteArrayOutputStream out = new ByteArrayOutputStream();
198-
byte[] buf = new byte[8192];
199-
while ((n = in.read(buf)) != -1) out.write(buf, 0, n);
200-
return new String(out.toByteArray(), StandardCharsets.UTF_8);
201-
} catch (IOException e) {
202-
throw new IllegalStateException("failed to load" + resource, e);
203-
}
204-
}
205172
}

0 commit comments

Comments
 (0)