summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSimon Rettberg2024-05-22 14:25:22 +0200
committerSimon Rettberg2024-05-22 14:25:22 +0200
commited16b59891350e9184d37b866fb8542215d995c6 (patch)
treeba35b891eda51ff333b1c77599a80ae302def7b6 /src/test
parentFix NPE (diff)
downloadmaster-sync-shared-ed16b59891350e9184d37b866fb8542215d995c6.tar.gz
master-sync-shared-ed16b59891350e9184d37b866fb8542215d995c6.tar.xz
master-sync-shared-ed16b59891350e9184d37b866fb8542215d995c6.zip
NanoHTTPD: Add test for ChunkedInputStream
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/fi/iki/elonen/ChunkedInputStreamTest.java31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/test/java/fi/iki/elonen/ChunkedInputStreamTest.java b/src/test/java/fi/iki/elonen/ChunkedInputStreamTest.java
new file mode 100644
index 0000000..d0fd9a1
--- /dev/null
+++ b/src/test/java/fi/iki/elonen/ChunkedInputStreamTest.java
@@ -0,0 +1,31 @@
+package fi.iki.elonen;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.IOException;
+import java.io.StringBufferInputStream;
+import java.nio.charset.StandardCharsets;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+public class ChunkedInputStreamTest
+{
+
+ @Test
+ @DisplayName( "Simple decoding test" )
+ public void testChunkedInput() throws IOException
+ {
+ String data = "4\r\nWiki\r\n7\r\npedia i\r\nB;1h\ra\nllo\r\nn \r\nchunks.\r\n0\r\n\r\n";
+ String expected = "Wikipedia in \r\nchunks.";
+ ChunkedInputStream stream = new ChunkedInputStream( new StringBufferInputStream( data ) );
+ StringBuilder sb = new StringBuilder();
+ int n;
+ byte[] buf = new byte[ 6 ];
+ while ( ( n = stream.read( buf ) ) > 0 ) {
+ sb.append( new String( buf, 0, n, StandardCharsets.US_ASCII ) );
+ }
+ assertEquals( sb.toString(), expected );
+ }
+
+}