Skip to content

Instantly share code, notes, and snippets.

@greghelton
Created December 26, 2011 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greghelton/1521810 to your computer and use it in GitHub Desktop.
Save greghelton/1521810 to your computer and use it in GitHub Desktop.
Java: JUnit test for StringReaderHelper.java
package us.greg;
import java.io.ByteArrayInputStream;
import java.net.URLEncoder;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class StreamReaderHelperTest {
String request = "http://localhost:8080/atm/prefs?customerID=123456789&atm=FG3781";
/*
* this is the test for my helper function
*/
@Test
public void streamReaderTest() {
try {
String testData = URLEncoder.encode(request, "UTF-8");
byte[] bytes = testData.getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
String data = StreamReaderHelper.readStream(bais);
assertEquals("http", data.substring(0, 4));
} catch(Exception e) {
fail();
}
assertTrue(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment