Skip to content

Commit

Permalink
#1127 unnecessary exceptions removed
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 11, 2022
1 parent 36f2d61 commit 1b87160
Show file tree
Hide file tree
Showing 43 changed files with 92 additions and 156 deletions.
7 changes: 3 additions & 4 deletions src/main/java/org/takes/facets/auth/Token.java
Expand Up @@ -52,9 +52,8 @@ public interface Token {
* Base64 encoded JSON output.
*
* @return The Token in JSON notation, Base64-encoded.
* @throws IOException If encoding fails
*/
byte[] encoded() throws IOException;
byte[] encoded();

/**
* JSON Object Signing and Encryption Header.
Expand Down Expand Up @@ -93,7 +92,7 @@ public JsonObject json() {
}

@Override
public byte[] encoded() throws IOException {
public byte[] encoded() {
return Base64.getEncoder().encode(
this.joseo.toString().getBytes(Charset.defaultCharset())
);
Expand Down Expand Up @@ -167,7 +166,7 @@ public JsonObject json() {
}

@Override
public byte[] encoded() throws IOException {
public byte[] encoded() {
return Base64.getEncoder().encode(
this.jwto.toString().getBytes(Charset.defaultCharset())
);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/takes/facets/auth/codecs/CcCompact.java
Expand Up @@ -44,7 +44,7 @@
public final class CcCompact implements Codec {

@Override
public byte[] encode(final Identity identity) throws IOException {
public byte[] encode(final Identity identity) {
final ByteArrayOutputStream data = new ByteArrayOutputStream();
try (DataOutputStream stream = new DataOutputStream(data)) {
stream.writeUTF(identity.urn());
Expand All @@ -60,7 +60,7 @@ public byte[] encode(final Identity identity) throws IOException {
}

@Override
public Identity decode(final byte[] bytes) throws IOException {
public Identity decode(final byte[] bytes) {
final Map<String, String> map = new HashMap<>(0);
try (DataInputStream stream = new DataInputStream(
new ByteArrayInputStream(bytes)
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/takes/facets/fork/FkHitRefresh.java
Expand Up @@ -215,9 +215,8 @@ public void touch() throws IOException {
/**
* Expired?
* @return TRUE if expired
* @throws IOException If fails
*/
private boolean expired() throws IOException {
private boolean expired() {
final boolean expired;
if (this.flag.isEmpty()) {
expired = true;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/takes/rq/RqPrint.java
Expand Up @@ -88,9 +88,8 @@ public String print() throws IOException {
/**
* Print it all.
* @param output Output stream
* @throws IOException If fails
*/
public void print(final OutputStream output) throws IOException {
public void print(final OutputStream output) {
new Unchecked<>(
new LengthOf(new TeeInput(this.text, new OutputTo(output)))
).value();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/rq/multipart/RqMtFake.java
Expand Up @@ -184,7 +184,7 @@ private FakeBody(final Request... parts) {
}

@Override
public InputStream body() throws IOException {
public InputStream body() {
return new InputStreamOf(this.content::value);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/takes/rs/RsJson.java
Expand Up @@ -104,9 +104,8 @@ public interface Source {
/**
* Get JSON value.
* @return JSON
* @throws IOException If fails
*/
JsonStructure toJson() throws IOException;
JsonStructure toJson();
}

}
9 changes: 2 additions & 7 deletions src/main/java/org/takes/rs/xe/XeTransform.java
Expand Up @@ -96,11 +96,7 @@ public boolean hasNext() {

@Override
public XeSource next() {
try {
return XeTransform.this.func.transform(origin.next());
} catch (final IOException ex) {
throw new IllegalStateException(ex);
}
return XeTransform.this.func.transform(origin.next());
}

@Override
Expand All @@ -120,8 +116,7 @@ public interface Func<T> {
* Transform an object.
* @param obj Object
* @return Xembly source
* @throws IOException If fails
*/
XeSource transform(T obj) throws IOException;
XeSource transform(T obj);
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/takes/rs/xe/XeWhen.java
Expand Up @@ -73,7 +73,7 @@ public Boolean value() {
source,
new Scalar<XeSource>() {
@Override
public XeSource value() throws IOException {
public XeSource value() {
return XeSource.EMPTY;
}
}
Expand All @@ -97,7 +97,7 @@ public XeSource value() {
},
new Scalar<XeSource>() {
@Override
public XeSource value() throws IOException {
public XeSource value() {
return XeSource.EMPTY;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/takes/servlet/HttpServletRequestFake.java
Expand Up @@ -319,39 +319,39 @@ public boolean isRequestedSessionIdFromUrl() {
@Override
public boolean authenticate(
final HttpServletResponse resp
) throws IOException, ServletException {
) {
throw new UnsupportedOperationException("#authenticate()");
}

@Override
public void login(
final String user,
final String password
) throws ServletException {
) {
throw new UnsupportedOperationException("#login()");
}

@Override
public void logout() throws ServletException {
public void logout() {
throw new UnsupportedOperationException("#logout()");
}

@Override
public Collection<Part> getParts() throws IOException, ServletException {
public Collection<Part> getParts() {
throw new UnsupportedOperationException("#getParts()");
}

@Override
public Part getPart(
final String name
) throws IOException, ServletException {
) {
throw new UnsupportedOperationException("#getPart()");
}

@Override
public <T extends HttpUpgradeHandler> T upgrade(
final Class<T> cls
) throws IOException, ServletException {
) {
throw new UnsupportedOperationException("#upgrade()");
}

Expand All @@ -373,7 +373,7 @@ public String getCharacterEncoding() {
@Override
public void setCharacterEncoding(
final String encoding
) throws UnsupportedEncodingException {
) {
throw new UnsupportedOperationException("#setCharacterEncoding()");
}

Expand Down Expand Up @@ -423,7 +423,7 @@ public String getScheme() {
}

@Override
public BufferedReader getReader() throws IOException {
public BufferedReader getReader() {
throw new UnsupportedOperationException("#getReader()");
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/takes/servlet/HttpServletResponseFake.java
Expand Up @@ -108,7 +108,7 @@ public void setStatus(final int code) {
public void sendError(
final int code,
final String reason
) throws IOException {
) {
this.response.set(
new RsWithStatus(
this.response.get(),
Expand Down Expand Up @@ -195,12 +195,12 @@ public String encodeRedirectUrl(final String url) {
}

@Override
public void sendError(final int code) throws IOException {
public void sendError(final int code) {
throw new UnsupportedOperationException("#sendError()");
}

@Override
public void sendRedirect(final String location) throws IOException {
public void sendRedirect(final String location) {
throw new UnsupportedOperationException("#sendRedirect()");
}

Expand Down Expand Up @@ -261,7 +261,7 @@ public String getContentType() {
}

@Override
public PrintWriter getWriter() throws IOException {
public PrintWriter getWriter() {
throw new UnsupportedOperationException("#getWriter()");
}

Expand Down Expand Up @@ -296,7 +296,7 @@ public int getBufferSize() {
}

@Override
public void flushBuffer() throws IOException {
public void flushBuffer() {
throw new UnsupportedOperationException("#flushBuffer()");
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/takes/tk/TkRedirect.java
Expand Up @@ -67,7 +67,7 @@ public TkRedirect(final String location, final int code) {
super(
new Take() {
@Override
public Response act(final Request req) throws IOException {
public Response act(final Request req) {
return new RsRedirect(location, code);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/takes/facets/auth/IdentityTest.java
Expand Up @@ -36,10 +36,9 @@ final class IdentityTest {

/**
* Identity.ANONYMOUS can be equal to itself.
* @throws IOException If some problem inside
*/
@Test
void equalsToItself() throws IOException {
void equalsToItself() {
MatcherAssert.assertThat(
Identity.ANONYMOUS,
new IsEqual<>(Identity.ANONYMOUS)
Expand Down
15 changes: 5 additions & 10 deletions src/test/java/org/takes/facets/auth/PsBasicDefaultTest.java
Expand Up @@ -36,10 +36,9 @@ final class PsBasicDefaultTest {

/**
* PsBasic.Default can accept a correct login/password pair.
* @throws Exception If fails
*/
@Test
void acceptsCorrectLoginPasswordPair() throws Exception {
void acceptsCorrectLoginPasswordPair() {
MatcherAssert.assertThat(
new PsBasic.Default(
new String[]{
Expand All @@ -60,10 +59,9 @@ void acceptsCorrectLoginPasswordPair() throws Exception {
/**
* PsBasic.Default can handle both <pre>%20</pre> and <pre>+</pre>
* variants of encoding spaces in constructor parameters.
* @throws Exception If fails
*/
@Test
void supportsBothKindsOfSpace() throws Exception {
void supportsBothKindsOfSpace() {
MatcherAssert.assertThat(
new PsBasic.Default(
new String[]{
Expand Down Expand Up @@ -94,10 +92,9 @@ void supportsBothKindsOfSpace() throws Exception {

/**
* PsBasic.Default can be entered by a user with a space in his name.
* @throws Exception If fails
*/
@Test
void supportsUsersWithSpacesInTheirNames() throws Exception {
void supportsUsersWithSpacesInTheirNames() {
MatcherAssert.assertThat(
new PsBasic.Default(
new String[]{
Expand Down Expand Up @@ -141,10 +138,9 @@ void supportsUrlencodedUrns() throws Exception {

/**
* PsBasic.Default can reject incorrect password.
* @throws Exception If fails
*/
@Test
void rejectsIncorrectPassword() throws Exception {
void rejectsIncorrectPassword() {
MatcherAssert.assertThat(
new PsBasic.Default(
new String[]{
Expand All @@ -160,10 +156,9 @@ void rejectsIncorrectPassword() throws Exception {

/**
* PsBasic.Default can reject a non-existing login.
* @throws Exception If fails
*/
@Test
void rejectsIncorrectLogin() throws Exception {
void rejectsIncorrectLogin() {
MatcherAssert.assertThat(
new PsBasic.Default(
new String[]{
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/org/takes/facets/auth/PsByFlagTest.java
Expand Up @@ -85,10 +85,9 @@ void flagIsFoundUserAuthenticated() throws Exception {

/**
* PsByFlag wraps response with authenticated user.
* @throws IOException If some problem inside
*/
@Test
void exitTest() throws IOException {
void exitTest() {
final Response response = new RsWithStatus(
new RsWithType(
new RsWithBody("<html>This is test response</html>"),
Expand All @@ -110,10 +109,9 @@ void exitTest() throws IOException {

/**
* Checks PsByFlag equals method.
* @throws Exception If some problem inside
*/
@Test
void mustEvaluateTrueEqualityTest() throws Exception {
void mustEvaluateTrueEqualityTest() {
final Map<Pattern, Pass> passes = new HashMap<>(1);
passes.put(Pattern.compile("key"), new PsFake(true));
new Assertion<>(
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/org/takes/facets/auth/TokenTest.java
Expand Up @@ -43,10 +43,9 @@
final class TokenTest {
/**
* JOSE header has correct algorithm name.
* @throws IOException If some problem inside
*/
@Test
void joseAlgorithm() throws IOException {
void joseAlgorithm() {
// @checkstyle MagicNumber (1 line)
final JsonObject jose = new Token.Jose(256).json();
MatcherAssert.assertThat(
Expand Down Expand Up @@ -75,11 +74,10 @@ void joseEncoded() throws IOException {

/**
* JWT header exp date is set correctly.
* @throws IOException If some problem inside
* @throws ParseException If date parsing fails
*/
@Test
void jwtExpiration() throws IOException, ParseException {
void jwtExpiration() throws ParseException {
final JsonObject jose = new Token.Jwt(
(Identity) new Identity.Simple("user"),
// @checkstyle MagicNumber (1 line)
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/takes/facets/auth/codecs/CcAesTest.java
Expand Up @@ -140,10 +140,9 @@ void encodesAndDecodes() throws Exception {

/**
* CcAES can throw the right exception.
* @throws Exception any unexpected exception to throw
*/
@Test
void throwsRightWhenBroken() throws Exception {
void throwsRightWhenBroken() {
Assertions.assertThrows(
DecodingException.class,
() -> new CcAes(
Expand Down
5 changes: 2 additions & 3 deletions src/test/java/org/takes/facets/auth/codecs/CcBase64Test.java
Expand Up @@ -134,10 +134,9 @@ void decodesNonBaseSixtyFourAlphabetSymbols() throws IOException {

/**
* Checks CcBase64 equals method.
* @throws Exception If some problem inside
*/
@Test
void mustEvaluateTrueEquality() throws Exception {
void mustEvaluateTrueEquality() {
new Assertion<>(
"Must evaluate equality of CcBase64 objects",
new CcBase64(new CcPlain()),
Expand All @@ -146,7 +145,7 @@ void mustEvaluateTrueEquality() throws Exception {
}

@Test
void mustEvaluateIdenticalHashCodes() throws Exception {
void mustEvaluateIdenticalHashCodes() {
new Assertion<>(
"Must evaluate identical hash codes",
new CcBase64(new CcPlain()).hashCode(),
Expand Down

0 comments on commit 1b87160

Please sign in to comment.