Skip to content

Commit

Permalink
#302 redundant exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jul 11, 2022
1 parent f668d47 commit b7d4c9d
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 90 deletions.
3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>jcabi-aspects</name>
<description>Collection of convenient and useful Java annotations
</description>
<description>Collection of convenient and useful Java annotations</description>
<issueManagement>
<system>github</system>
<url>https://github.com/jcabi/jcabi-aspects/issues</url>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/aspects/aj/MethodAsyncRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public Object wrap(final ProceedingJoinPoint point) {
// @checkstyle AnonInnerLength (23 lines)
new Callable<Object>() {
@Override
public Object call() throws Exception {
public Object call() {
Object returned = null;
try {
final Object result = point.proceed();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/aspects/aj/MethodScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void run() {
}

@Override
public void close() throws IOException {
public void close() {
this.executor.shutdown();
final long begin = System.currentTimeMillis();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public final class QuietExceptionsLogger {
*
* @param point Joint point
* @return The result of call
* @throws Throwable If something goes wrong inside
*/
@Around
(
Expand All @@ -67,7 +66,7 @@ public final class QuietExceptionsLogger {
+ " && @annotation(com.jcabi.aspects.Quietly)"
)
@SuppressWarnings("PMD.AvoidCatchingThrowable")
public Object wrap(final ProceedingJoinPoint point) throws Throwable {
public Object wrap(final ProceedingJoinPoint point) {
if (!MethodSignature.class.cast(point.getSignature()).getReturnType()
.equals(Void.TYPE)) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
/**
* Annotation processor that checks whether methods annotated with
* {@link com.jcabi.aspects.Async} have void or
* {@link java.util.concurrent.Future} return types.
* {@link Future} return types.
*
* @since 0.17
*/
Expand Down Expand Up @@ -93,9 +93,9 @@ private void checkMethods(final RoundEnvironment env,
}

/**
* Is the given type assignable from {@link java.util.concurrent.Future}?
* Is the given type assignable from {@link Future}?
* @param type The type to check.
* @return If it's assingable from Future.
* @return If it's assignable from Future.
*/
private boolean assignableToFuture(final TypeMirror type) {
final Types types = this.processingEnv.getTypeUtils();
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/com/jcabi/aspects/CacheableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@ public final class CacheableTest {

/**
* Cacheable can cache calls.
* @throws Exception If something goes wrong
*/
@Test
public void cachesSimpleCall() throws Exception {
public void cachesSimpleCall() {
final CacheableTest.Foo foo = new CacheableTest.Foo(1L);
final String first = foo.get().toString();
MatcherAssert.assertThat(first, Matchers.equalTo(foo.get().toString()));
Expand Down Expand Up @@ -105,10 +104,9 @@ public void asyncUpdateCacheSimpleCall() throws Exception {

/**
* Cacheable can cache static calls.
* @throws Exception If something goes wrong
*/
@Test
public void cachesSimpleStaticCall() throws Exception {
public void cachesSimpleStaticCall() {
final String first = CacheableTest.Foo.staticGet();
MatcherAssert.assertThat(
first,
Expand Down Expand Up @@ -172,10 +170,9 @@ public void cachesJustOnceInParallelThreads() throws Exception {

/**
* Cacheable can flush with a static trigger.
* @throws Exception If something goes wrong
*/
@Test
public void flushesWithStaticTrigger() throws Exception {
public void flushesWithStaticTrigger() {
final CacheableTest.Bar bar = new CacheableTest.Bar();
MatcherAssert.assertThat(
bar.get(),
Expand Down
20 changes: 5 additions & 15 deletions src/test/java/com/jcabi/aspects/JSR303Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@ public final class JSR303Test {

/**
* NotNull can throw when invalid method parameters.
*
* @throws Exception If something goes wrong
*/
@Test
public void throwsWhenMethodParametersAreInvalid() throws Exception {
public void throwsWhenMethodParametersAreInvalid() {
Assertions.assertThrows(
ConstraintViolationException.class,
() -> new JSR303Test.Foo().foo(null)
Expand All @@ -72,11 +70,9 @@ public void throwsWhenMethodParametersAreInvalid() throws Exception {

/**
* NotNull can throw when regex doesn't match.
*
* @throws Exception If something goes wrong
*/
@Test
public void throwsWhenRegularExpressionDoesntMatch() throws Exception {
public void throwsWhenRegularExpressionDoesntMatch() {
Assertions.assertThrows(
ConstraintViolationException.class,
() -> new JSR303Test.Foo().foo("some text")
Expand All @@ -85,21 +81,17 @@ public void throwsWhenRegularExpressionDoesntMatch() throws Exception {

/**
* NotNull can pass for valid parameters.
*
* @throws Exception If something goes wrong
*/
@Test
public void passesWhenMethodParametersAreValid() throws Exception {
public void passesWhenMethodParametersAreValid() {
new JSR303Test.Foo().foo("123");
}

/**
* NotNull can validate method output.
*
* @throws Exception If something goes wrong
*/
@Test
public void validatesOutputForNonNull() throws Exception {
public void validatesOutputForNonNull() {
Assertions.assertThrows(
ConstraintViolationException.class,
() -> new JSR303Test.Foo().nullValue()
Expand All @@ -108,11 +100,9 @@ public void validatesOutputForNonNull() throws Exception {

/**
* NotNull can ignore methods that return VOID.
*
* @throws Exception If something goes wrong
*/
@Test
public void ignoresVoidResponses() throws Exception {
public void ignoresVoidResponses() {
new JSR303Test.Foo().voidAlways();
}

Expand Down
18 changes: 6 additions & 12 deletions src/test/java/com/jcabi/aspects/LoggableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,17 @@ public final class LoggableTest {

/**
* Loggable can log simple calls.
* @throws Exception If something goes wrong
*/
@Test
public void logsSimpleCall() throws Exception {
public void logsSimpleCall() {
new LoggableTest.Foo().revert("hello");
}

/**
* Loggable can ignore toString() methods.
* @throws Exception If something goes wrong
*/
@Test
public void ignoresToStringMethods() throws Exception {
public void ignoresToStringMethods() {
new LoggableTest.Foo().self();
}

Expand All @@ -86,19 +84,17 @@ public void logsStaticMethods() throws Exception {

/**
* Loggable can ignore inherited methods.
* @throws Exception If something goes wrong
*/
@Test
public void doesntLogInheritedMethods() throws Exception {
public void doesntLogInheritedMethods() {
new LoggableTest.Foo().parentText();
}

/**
* Loggable can ignore some exceptions.
* @throws Exception If something goes wrong
*/
@Test
public void ignoresSomeExceptions() throws Exception {
public void ignoresSomeExceptions() {
Assertions.assertThrows(
IllegalStateException.class,
() -> new LoggableTest.Foo().doThrow()
Expand All @@ -124,10 +120,9 @@ public void logsDurationWithSpecifiedTimeUnit() throws Exception {

/**
* Loggable can log toString method.
* @throws Exception If something goes wrong
*/
@Test
public void logsToStringResult() throws Exception {
public void logsToStringResult() {
final StringWriter writer = new StringWriter();
org.apache.log4j.Logger.getRootLogger().addAppender(
new WriterAppender(new SimpleLayout(), writer)
Expand Down Expand Up @@ -267,10 +262,9 @@ public static String text() throws Exception {
/**
* Method annotated with Loggable specifying explicit logger name.
* @return A String
* @throws Exception If terminated
*/
@Loggable(value = Loggable.DEBUG, name = "test-logger", prepend = true)
public static String explicitLoggerName() throws Exception {
public static String explicitLoggerName() {
return LoggableTest.Foo.hiddenText();
}

Expand Down
6 changes: 2 additions & 4 deletions src/test/java/com/jcabi/aspects/RetryOnFailureTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ public final class RetryOnFailureTest {

/**
* RetryOnFailure can force duplicate execution of the same method.
* @throws Exception If something goes wrong
*/
@Test
public void executesMethodManyTimes() throws Exception {
public void executesMethodManyTimes() {
final AtomicInteger count = new AtomicInteger();
new Runnable() {
@Override
Expand All @@ -65,10 +64,9 @@ public void run() {

/**
* RetryOnFailure can retry when Error types are thrown.
* @throws Exception If something goes wrong
*/
@Test
public void retriesOnError() throws Exception {
public void retriesOnError() {
final AtomicInteger count = new AtomicInteger();
new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
package com.jcabi.aspects;

import java.io.Closeable;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import org.hamcrest.MatcherAssert;
Expand Down Expand Up @@ -102,7 +101,7 @@ public void run() {
}

@Override
public void close() throws IOException {
public void close() {
this.counter.set(-1L);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/jcabi/aspects/TimeableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ public final class TimeableTest {

/**
* Timeable annotation can interrupt a long method.
* @throws Exception If something goes wrong
*/
@Test
public void interruptsLongRunningMethod() throws Exception {
public void interruptsLongRunningMethod() {
Assertions.assertThrows(
InterruptedException.class,
() -> this.slow()
Expand Down
20 changes: 5 additions & 15 deletions src/test/java/com/jcabi/aspects/UnitedThrowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ public final class UnitedThrowTest {

/**
* UnitedThrow can rethrow exception that is a subclass of declared one.
* @throws Exception If something goes wrong
*/
@Test
public void rethrowsDeclaredException() throws Exception {
public void rethrowsDeclaredException() {
Assertions.assertThrows(
IOException.class,
() -> new UnitedThrowTest.Thrower().file()
Expand All @@ -56,10 +55,9 @@ public void rethrowsDeclaredException() throws Exception {

/**
* UnitedThrow can throw first declared exception.
* @throws Exception If something goes wrong
*/
@Test
public void throwsDeclaredException() throws Exception {
public void throwsDeclaredException() {
Assertions.assertThrows(
IOException.class,
() -> new UnitedThrowTest.Thrower().save()
Expand All @@ -68,10 +66,9 @@ public void throwsDeclaredException() throws Exception {

/**
* UnitedThrow can throw configured exception.
* @throws Exception If something goes wrong
*/
@Test
public void throwsConfiguredException() throws Exception {
public void throwsConfiguredException() {
Assertions.assertThrows(
IOException.class,
() -> new UnitedThrowTest.Thrower().multiple()
Expand All @@ -80,10 +77,9 @@ public void throwsConfiguredException() throws Exception {

/**
* UnitedThrow can throw IllegalStateException when no exception declared.
* @throws Exception If something goes wrong
*/
@Test
public void throwsIllegalStateException() throws Exception {
public void throwsIllegalStateException() {
Assertions.assertThrows(
IllegalStateException.class,
() -> new UnitedThrowTest.Thrower().def()
Expand All @@ -92,11 +88,9 @@ public void throwsIllegalStateException() throws Exception {

/**
* UnitedThrow can encapsulate thrown exception inside declared one.
* @throws Exception If something goes wrong
*/
@Test
public void throwsOriginalExceptionEncapsulatedInsideDeclared()
throws Exception {
public void throwsOriginalExceptionEncapsulatedInsideDeclared() {
try {
new UnitedThrowTest.Thrower().encapsulate();
} catch (final IOException ex) {
Expand All @@ -114,7 +108,6 @@ public void throwsOriginalExceptionEncapsulatedInsideDeclared()
private static final class Thrower {
/**
* Test method.
* @throws IOException In case of exception.
*/
@UnitedThrow
public void save() throws IOException {
Expand All @@ -132,8 +125,6 @@ public void file() throws IOException {

/**
* Test method.
* @throws InterruptedException In case of exception.
* @throws IOException In case of exception.
* @checkstyle ThrowsCountCheck (3 lines)
*/
@UnitedThrow(IOException.class)
Expand All @@ -151,7 +142,6 @@ public void def() {

/**
* Test method.
* @throws IOException In case of exception.
*/
@UnitedThrow(IOException.class)
public void encapsulate() throws IOException {
Expand Down

0 comments on commit b7d4c9d

Please sign in to comment.