aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2016-01-20 11:38:35 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2016-01-20 11:38:35 +0900
commit0d77b4e5c87528f2d3e810742997483f403c8968 (patch)
tree09e7d1f1b0f677f16ae7e4ab1245c7d94dc59062 /org.eclipse.jgit.test/tst/org/eclipse
parent7c21aeb5083ca5ec3a8eaf54ab2ba8d2f84ce87a (diff)
downloadjgit-0d77b4e5c87528f2d3e810742997483f403c8968.tar.gz
jgit-0d77b4e5c87528f2d3e810742997483f403c8968.zip
SideBandOutputStreamTest: Use try-with-resource
Factor out the creation of the SideBandOutputStream objects into a utility method that wraps it in a try-with-resource. Remove the "unused" suppression that is now unnecessary, and add declaration that the tests methods can throw Exception. Change-Id: Iff02e4e3532bd6ab6e423f197e70d44c4f328d0b Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java27
1 files changed, 16 insertions, 11 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java
index 3661677cd9..d2c3a0b92f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/SideBandOutputStreamTest.java
@@ -195,25 +195,31 @@ public class SideBandOutputStreamTest {
assertEquals(1, flushCnt[0]);
}
- @SuppressWarnings("unused")
+ private void createSideBandOutputStream(int chan, int sz, OutputStream os)
+ throws Exception {
+ try (SideBandOutputStream s = new SideBandOutputStream(chan, sz, os)) {
+ // Unused
+ }
+ }
+
@Test
- public void testConstructor_RejectsBadChannel() {
+ public void testConstructor_RejectsBadChannel() throws Exception {
try {
- new SideBandOutputStream(-1, MAX_BUF, rawOut);
+ createSideBandOutputStream(-1, MAX_BUF, rawOut);
fail("Accepted -1 channel number");
} catch (IllegalArgumentException e) {
assertEquals("channel -1 must be in range [1, 255]", e.getMessage());
}
try {
- new SideBandOutputStream(0, MAX_BUF, rawOut);
+ createSideBandOutputStream(0, MAX_BUF, rawOut);
fail("Accepted 0 channel number");
} catch (IllegalArgumentException e) {
assertEquals("channel 0 must be in range [1, 255]", e.getMessage());
}
try {
- new SideBandOutputStream(256, MAX_BUF, rawOut);
+ createSideBandOutputStream(256, MAX_BUF, rawOut);
fail("Accepted 256 channel number");
} catch (IllegalArgumentException e) {
assertEquals("channel 256 must be in range [1, 255]", e
@@ -221,32 +227,31 @@ public class SideBandOutputStreamTest {
}
}
- @SuppressWarnings("unused")
@Test
- public void testConstructor_RejectsBadBufferSize() {
+ public void testConstructor_RejectsBadBufferSize() throws Exception {
try {
- new SideBandOutputStream(CH_DATA, -1, rawOut);
+ createSideBandOutputStream(CH_DATA, -1, rawOut);
fail("Accepted -1 for buffer size");
} catch (IllegalArgumentException e) {
assertEquals("packet size -1 must be >= 5", e.getMessage());
}
try {
- new SideBandOutputStream(CH_DATA, 0, rawOut);
+ createSideBandOutputStream(CH_DATA, 0, rawOut);
fail("Accepted 0 for buffer size");
} catch (IllegalArgumentException e) {
assertEquals("packet size 0 must be >= 5", e.getMessage());
}
try {
- new SideBandOutputStream(CH_DATA, 1, rawOut);
+ createSideBandOutputStream(CH_DATA, 1, rawOut);
fail("Accepted 1 for buffer size");
} catch (IllegalArgumentException e) {
assertEquals("packet size 1 must be >= 5", e.getMessage());
}
try {
- new SideBandOutputStream(CH_DATA, Integer.MAX_VALUE, rawOut);
+ createSideBandOutputStream(CH_DATA, Integer.MAX_VALUE, rawOut);
fail("Accepted " + Integer.MAX_VALUE + " for buffer size");
} catch (IllegalArgumentException e) {
assertEquals(MessageFormat.format(