Skip to content

Commit

Permalink
Fix checkstyle issues and compiler warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikaël Francoeur committed Mar 19, 2024
1 parent b2f8753 commit a159dd1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.Serializable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -54,7 +53,6 @@
import org.springframework.util.ClassUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.ReflectionUtils;

/**
* CGLIB-based {@link AopProxy} implementation for the Spring AOP framework.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
package org.springframework.aop.framework;
/*
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import static java.util.Objects.requireNonNull;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
package org.springframework.aop.framework;

import java.io.Serial;
import java.lang.reflect.Proxy;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Collection;
import java.util.Set;
import java.util.Objects;

import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInterceptor;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.lang.Nullable;

import static org.mockito.BDDMockito.doAnswer;
import static org.mockito.BDDMockito.doThrow;
import static org.mockito.BDDMockito.mock;

abstract class ProxyExceptionHandlingTests implements WithAssertions {

private static final RuntimeException uncheckedException = new RuntimeException();
Expand All @@ -35,7 +50,7 @@ abstract class ProxyExceptionHandlingTests implements WithAssertions {
@Nullable
private Throwable throwableSeenByCaller;

static class ObjenesisCglibAopProxyTest extends ProxyExceptionHandlingTests {
static class ObjenesisCglibAopProxyTests extends ProxyExceptionHandlingTests {
@BeforeEach
void beforeEach() {
proxyFactory.setProxyTargetClass(true);
Expand All @@ -47,14 +62,15 @@ protected void assertProxyType(Object proxy) {
}
}

static class JdkAopProxyTest extends ProxyExceptionHandlingTests {
static class JdkAopProxyTests extends ProxyExceptionHandlingTests {
@Override
protected void assertProxyType(Object proxy) {
assertThat(Proxy.isProxyClass(proxy.getClass())).isTrue();
}
}

protected void assertProxyType(Object proxy) {};
protected void assertProxyType(Object proxy) {
}

@BeforeEach
void beforeEach() {
Expand Down Expand Up @@ -112,7 +128,8 @@ private MethodInterceptor captureThrowable() {
return invocation -> {
try {
return invocation.proceed();
} catch (Exception e) {
}
catch (Exception e) {
throwableSeenByInterceptor = e;
throw e;
}
Expand Down Expand Up @@ -161,7 +178,7 @@ void targetThrowsUncheckedException() throws DeclaredCheckedException {
}

private void invokeProxy() {
throwableSeenByCaller = catchThrowable(() -> requireNonNull(proxy).doSomething());
throwableSeenByCaller = catchThrowable(() -> Objects.requireNonNull(proxy).doSomething());
}

private Answer<?> sneakyThrow(@SuppressWarnings("SameParameterValue") Throwable throwable) {
Expand All @@ -182,9 +199,13 @@ protected interface MyInterface {
}

protected static class UndeclaredCheckedException extends Exception {
@Serial
private static final long serialVersionUID = -4199611059122356651L;
}

protected static class DeclaredCheckedException extends Exception {
@Serial
private static final long serialVersionUID = 8851375818059230518L;
}

}

0 comments on commit a159dd1

Please sign in to comment.