|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2018 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.util;
|
18 | 18 |
|
| 19 | +import java.io.ByteArrayInputStream; |
19 | 20 | import java.io.ByteArrayOutputStream;
|
20 | 21 | import java.io.IOException;
|
21 | 22 | import java.io.InputStream;
|
| 23 | +import java.nio.charset.StandardCharsets; |
22 | 24 |
|
23 |
| -import org.junit.Before; |
24 | 25 | import org.junit.Test;
|
25 | 26 |
|
26 | 27 | import static org.junit.Assert.*;
|
27 | 28 |
|
28 | 29 | /**
|
29 |
| - * Test suite for {@link FastByteArrayOutputStream} |
| 30 | + * Test suite for {@link FastByteArrayOutputStream}. |
| 31 | + * |
30 | 32 | * @author Craig Andrews
|
31 | 33 | */
|
32 | 34 | public class FastByteArrayOutputStreamTests {
|
33 | 35 |
|
34 | 36 | private static final int INITIAL_CAPACITY = 256;
|
35 | 37 |
|
36 |
| - private FastByteArrayOutputStream os; |
37 |
| - |
38 |
| - private byte[] helloBytes; |
| 38 | + private final FastByteArrayOutputStream os = new FastByteArrayOutputStream(INITIAL_CAPACITY);; |
39 | 39 |
|
40 |
| - |
41 |
| - @Before |
42 |
| - public void setUp() throws Exception { |
43 |
| - this.os = new FastByteArrayOutputStream(INITIAL_CAPACITY); |
44 |
| - this.helloBytes = "Hello World".getBytes("UTF-8"); |
45 |
| - } |
| 40 | + private final byte[] helloBytes = "Hello World".getBytes(StandardCharsets.UTF_8);; |
46 | 41 |
|
47 | 42 |
|
48 | 43 | @Test
|
@@ -137,6 +132,15 @@ public void getInputStreamRead() throws Exception {
|
137 | 132 | assertEquals(inputStream.read(), this.helloBytes[3]);
|
138 | 133 | }
|
139 | 134 |
|
| 135 | + @Test |
| 136 | + public void getInputStreamReadBytePromotion() throws Exception { |
| 137 | + byte[] bytes = new byte[] { -1 }; |
| 138 | + this.os.write(bytes); |
| 139 | + InputStream inputStream = this.os.getInputStream(); |
| 140 | + ByteArrayInputStream bais = new ByteArrayInputStream(bytes); |
| 141 | + assertEquals(bais.read(), inputStream.read()); |
| 142 | + } |
| 143 | + |
140 | 144 | @Test
|
141 | 145 | public void getInputStreamReadAll() throws Exception {
|
142 | 146 | this.os.write(this.helloBytes);
|
|
0 commit comments