Skip to content

Commit

Permalink
Add unit test to ensure PumpReader works correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-gh committed Sep 20, 2017
1 parent 938eeca commit bb59951
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions terminal/src/test/java/org/jline/utils/PumpReaderTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2002-2017, the original author or authors.
*
* This software is distributable under the BSD license. See the terms of the
* BSD license in the documentation provided with this software.
*
* http://www.opensource.org/licenses/bsd-license.php
*/
package org.jline.utils;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

public class PumpReaderTest {

private PumpReader writeInput() {
PumpReader pump = new PumpReader();
PrintWriter writer = new PrintWriter(pump.getWriter());

// Write some input
writer.println("Hello world!");
writer.println("㐀");

return pump;
}

@Test
public void testReader() throws IOException {
PumpReader pump = writeInput();

// Read it again
BufferedReader reader = new BufferedReader(pump);
assertEquals("Hello world!", reader.readLine());
assertEquals("㐀", reader.readLine());
}

@Test
public void testInputStream() throws IOException {
PumpReader pump = writeInput();

// Read it using an input stream
BufferedReader reader = new BufferedReader(new InputStreamReader(pump.createInputStream(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
assertEquals("Hello world!", reader.readLine());
assertEquals("㐀", reader.readLine());
}

}

0 comments on commit bb59951

Please sign in to comment.