You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@juneau.apache.org by gg...@apache.org on 2023/06/23 18:02:50 UTC
[juneau] 01/04: [juneau-utest] Throw IllegalArgumentException instead of RuntimeException
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
commit b2cbd121b5524b7851c281bdfe83123df6b0525c
Author: Gary Gregory <gg...@rocketsoftware.com>
AuthorDate: Fri Jun 23 13:58:01 2023 -0400
[juneau-utest] Throw IllegalArgumentException instead of
RuntimeException
---
.../juneau/CloseableByteArrayInputStream.java | 2 +-
.../org/apache/juneau/CloseableStringReader.java | 21 ++++++++++++---------
.../rest/annotation/BeanConfig_Swaps_Test.java | 6 +++---
.../juneau/rest/annotation/RestPostCall_Test.java | 4 ++--
.../juneau/rest/annotation/RestPreCall_Test.java | 4 ++--
.../juneau/rest/annotation/RestStartCall_Test.java | 4 ++--
6 files changed, 22 insertions(+), 19 deletions(-)
diff --git a/juneau-utest/src/test/java/org/apache/juneau/CloseableByteArrayInputStream.java b/juneau-utest/src/test/java/org/apache/juneau/CloseableByteArrayInputStream.java
index 716d4a0cc..8c84c3e04 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/CloseableByteArrayInputStream.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/CloseableByteArrayInputStream.java
@@ -27,7 +27,7 @@ public class CloseableByteArrayInputStream extends ByteArrayInputStream {
@Override
public int read() {
if (isClosed)
- throw new RuntimeException("Stream is closed");
+ throw new IllegalStateException("Stream is closed");
return super.read();
}
diff --git a/juneau-utest/src/test/java/org/apache/juneau/CloseableStringReader.java b/juneau-utest/src/test/java/org/apache/juneau/CloseableStringReader.java
index 836a3b56e..67d536413 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/CloseableStringReader.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/CloseableStringReader.java
@@ -24,22 +24,25 @@ public class CloseableStringReader extends StringReader {
super(in);
}
+ private void checkOpen() {
+ if (isClosed)
+ throw new IllegalStateException("Reader is closed");
+ }
+
+ @Override
+ public void close() {
+ isClosed = true;
+ }
+
@Override
public int read() throws IOException {
- if (isClosed)
- throw new RuntimeException("Reader is closed");
+ checkOpen();
return super.read();
}
@Override
public int read(char[] cbuf, int off, int len) throws IOException {
- if (isClosed)
- throw new RuntimeException("Reader is closed");
+ checkOpen();
return super.read(cbuf, off, len);
}
-
- @Override
- public void close() {
- isClosed = true;
- }
}
\ No newline at end of file
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java
index 2367e204f..c7ba277f0 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/BeanConfig_Swaps_Test.java
@@ -46,7 +46,7 @@ public class BeanConfig_Swaps_Test {
@Override /* ObjectSwap */
public A unswap(BeanSession session, String in, ClassMeta<?> hint) throws ParseException {
if (! in.startsWith("A1"))
- throw new RuntimeException("Invalid input for SwapA1!");
+ throw new IllegalArgumentException("Invalid input for SwapA1!");
A a = new A();
a.f1 = Integer.parseInt(in.substring(3));
return a;
@@ -61,7 +61,7 @@ public class BeanConfig_Swaps_Test {
@Override /* ObjectSwap */
public A unswap(BeanSession session, String in, ClassMeta<?> hint) throws ParseException {
if (! in.startsWith("A2"))
- throw new RuntimeException("Invalid input for SwapA2!");
+ throw new IllegalArgumentException("Invalid input for SwapA2!");
A a = new A();
a.f1 = Integer.parseInt(in.substring(3));
return a;
@@ -76,7 +76,7 @@ public class BeanConfig_Swaps_Test {
@Override /* ObjectSwap */
public A unswap(BeanSession session, String in, ClassMeta<?> hint) throws ParseException {
if (! in.startsWith("A3"))
- throw new RuntimeException("Invalid input for SwapA3!");
+ throw new IllegalArgumentException("Invalid input for SwapA3!");
A a = new A();
a.f1 = Integer.parseInt(in.substring(3));
return a;
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPostCall_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPostCall_Test.java
index 88439a75c..086fd10e4 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPostCall_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPostCall_Test.java
@@ -42,7 +42,7 @@ public class RestPostCall_Test {
res.setHeader("post3-called", ""+post3Called);
post3Called = false;
if (res.getHeader("post4-called") != null)
- throw new RuntimeException("post4 called multiple times.");
+ throw new IllegalArgumentException("post4 called multiple times.");
res.setHeader("post4-called", "true");
}
@RestGet(path="/")
@@ -62,7 +62,7 @@ public class RestPostCall_Test {
res.setHeader("post1-called", ""+post1Called);
post1Called = false;
if (res.getHeader("post2-called") != null)
- throw new RuntimeException("post2 called multiple times.");
+ throw new IllegalArgumentException("post2 called multiple times.");
res.setHeader("post2-called", "true");
}
}
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPreCall_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPreCall_Test.java
index d85305656..1952cc77c 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPreCall_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestPreCall_Test.java
@@ -43,7 +43,7 @@ public class RestPreCall_Test {
res.setHeader("pre3-called", ""+pre3Called);
pre3Called = false;
if (res.getHeader("pre4-called") != null)
- throw new RuntimeException("pre4 called multiple times.");
+ throw new IllegalArgumentException("pre4 called multiple times.");
res.setHeader("pre4-called", "true");
}
@RestGet(path="/")
@@ -67,7 +67,7 @@ public class RestPreCall_Test {
res.setHeader("pre1-called", ""+pre1Called);
pre1Called = false;
if (res.getHeader("pre2-called") != null)
- throw new RuntimeException("pre2 called multiple times.");
+ throw new IllegalArgumentException("pre2 called multiple times.");
res.setHeader("pre2-called", "true");
}
}
diff --git a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestStartCall_Test.java b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestStartCall_Test.java
index ddd8794cd..f1f6dde87 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestStartCall_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/rest/annotation/RestStartCall_Test.java
@@ -42,7 +42,7 @@ public class RestStartCall_Test {
res.setHeader("start3-called", ""+start3Called);
start3Called = false;
if (res.getHeader("start4-called") != null)
- throw new RuntimeException("start4 called multiple times.");
+ throw new IllegalArgumentException("start4 called multiple times.");
res.setHeader("start4-called", "true");
}
@RestGet(path="/")
@@ -66,7 +66,7 @@ public class RestStartCall_Test {
res.setHeader("start1-called", ""+start1Called);
start1Called = false;
if (res.getHeader("start2-called") != null)
- throw new RuntimeException("start2 called multiple times.");
+ throw new IllegalArgumentException("start2 called multiple times.");
res.setHeader("start2-called", "true");
}
}