Skip to content

Commit e7ad274

Browse files
committed
update JUnit test
1 parent 869176e commit e7ad274

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ Find more detail at:
1313
* [Set Up Eclipse, IntelliJ And NetBeans For Java 9](https://howtoprogram.xyz/2017/09/24/set-up-eclipse-intellij-and-netbeans-for-java-9/)
1414
* [Create Immutable Lists In Java 9 By Static Factory Methods](https://howtoprogram.xyz/2017/09/24/java-9-create-immutable-lists-static-factory-method/)
1515
* [Java 9 Example With Maven And JUnit 5](https://howtoprogram.xyz/2017/09/23/java-9-maven-junit-5-example/)
16+
* [Copy Streams In Java 9 With The InputStream.transferTo() Method](https://howtoprogram.xyz/2017/10/01/java-9-inputstream-transferto-copy-streams/)
1617

java9-language-features-examples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Demonstration for:
44

55
[Create Immutable Lists In Java 9 By Static Factory Methods](https://howtoprogram.xyz/2017/09/24/java-9-create-immutable-lists-static-factory-method/)
6+
67
[Copy Streams In Java 9 With The InputStream.transferTo() Method](https://howtoprogram.xyz/2017/10/01/java-9-inputstream-transferto-copy-streams/)
78

89

java9-language-features-examples/src/test/java/com/howtoprogram/io/InputStreamTransferToTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@
33
import org.junit.jupiter.api.Test;
44

55
import java.io.*;
6+
import java.util.Arrays;
67

78
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
810

911
public class InputStreamTransferToTest {
1012

1113
@Test
1214
public void testTransferTo() throws IOException {
1315

14-
ByteArrayInputStream bis = new ByteArrayInputStream("Hello Java 9".getBytes());
16+
byte [] inBytes = "Hello Java 9".getBytes();
17+
ByteArrayInputStream bis = new ByteArrayInputStream(inBytes);
1518
ByteArrayOutputStream bos = new ByteArrayOutputStream();
1619
try {
1720

21+
bis.transferTo(bos);
1822

19-
long count = bis.transferTo(bos);
20-
21-
byte[] bytes = bos.toByteArray();
22-
23-
assertEquals(count, bytes.length);
23+
byte[] outBytes = bos.toByteArray();
2424

25+
assertTrue(Arrays.equals(inBytes,outBytes));
2526

2627
} finally {
2728
try {
@@ -43,16 +44,16 @@ public void testTransferTo() throws IOException {
4344

4445
@Test
4546
public void testTransferToJava9Syntax() throws IOException {
46-
47-
ByteArrayInputStream bis = new ByteArrayInputStream("Hello Java 9".getBytes());
47+
byte [] inBytes = "Hello Java 9".getBytes();
48+
ByteArrayInputStream bis = new ByteArrayInputStream(inBytes);
4849
ByteArrayOutputStream bos = new ByteArrayOutputStream();
4950

5051
try (bis; bos) {
5152

5253
long count = bis.transferTo(bos);
5354

54-
byte[] bytes = bos.toByteArray();
55-
assertEquals(count, bytes.length);
55+
byte[] outBytes = bos.toByteArray();
56+
assertTrue(Arrays.equals(inBytes,outBytes));
5657
}
5758
}
5859
}

0 commit comments

Comments
 (0)