Skip to content

Commit a5fbe16

Browse files
committed
Java tests generate testChars.ser.gz
Will be used for GZip input test
1 parent c4d8f84 commit a5fbe16

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

tests/java/src/test/java/OneTest.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import java.awt.event.WindowAdapter;
22
import java.awt.event.WindowEvent;
33
import java.io.ByteArrayOutputStream;
4+
import java.io.FileInputStream;
45
import java.io.FileOutputStream;
56
import java.io.IOException;
67
import java.io.ObjectInputStream;
@@ -22,6 +23,7 @@
2223
import java.util.TreeSet;
2324
import java.util.Vector;
2425
import java.util.Random;
26+
import java.util.zip.GZIPOutputStream;
2527

2628
import javax.swing.JScrollPane;
2729
import javax.swing.SwingUtilities;
@@ -168,10 +170,16 @@ private void writeObject(final ObjectOutputStream oos)
168170

169171
ObjectOutputStream oos;
170172

173+
/**
174+
* Returns the name of the file where to serialize the test content
175+
*/
176+
private String getTestFileName() {
177+
return name.getMethodName() + ".ser";
178+
}
179+
171180
@Before
172181
public void setUp() throws Exception {
173-
oos = new ObjectOutputStream(fos = new FileOutputStream(
174-
name.getMethodName() + ".ser"));
182+
oos = new ObjectOutputStream(fos = new FileOutputStream(getTestFileName()));
175183
}
176184

177185
@Test
@@ -208,6 +216,20 @@ public void testChar() throws IOException {
208216
public void testChars() throws IOException {
209217
oos.writeChars("python-javaobj");
210218
oos.close();
219+
220+
// Also compress the file
221+
final String serializedFileName = getTestFileName();
222+
final String gzippedFileName = serializedFileName + ".gz";
223+
224+
try (final GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(gzippedFileName))){
225+
try (final FileInputStream in = new FileInputStream(serializedFileName)){
226+
final byte[] buffer = new byte[1024];
227+
int len;
228+
while((len = in.read(buffer)) != -1){
229+
out.write(buffer, 0, len);
230+
}
231+
}
232+
}
211233
}
212234

213235
@Test
@@ -389,7 +411,7 @@ public void windowClosing(final WindowEvent e) {
389411
});
390412
}
391413

392-
414+
393415
/**
394416
* Tests the pull request #38 by @UruDev:
395417
* Add support for custom writeObject

tests/java/testChars.ser.gz

52 Bytes
Binary file not shown.

tests/testChars.ser.gz

52 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)