Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jun 2, 2023
1 parent c685525 commit 4b8adf2
Show file tree
Hide file tree
Showing 27 changed files with 127 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ public String[] getParameterNames(Constructor<?> ctor) {
}


private void bindParameterName(int index, String name) {
private void bindParameterName(int index, @Nullable String name) {
this.parameterNameBindings[index] = name;
this.numberOfRemainingUnboundArguments--;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 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.
Expand Down Expand Up @@ -63,8 +63,8 @@ public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requi
(field != null ? new TypeDescriptor(field) : TypeDescriptor.valueOf(requiredType)));
}

@Nullable
@Override
@Nullable
public <T> T convertIfNecessary(@Nullable Object value, @Nullable Class<T> requiredType,
@Nullable TypeDescriptor typeDescriptor) throws TypeMismatchException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements
private boolean singletonsCurrentlyInDestruction = false;

/** Disposable bean instances: bean name to disposable instance. */
private final Map<String, Object> disposableBeans = new LinkedHashMap<>();
private final Map<String, DisposableBean> disposableBeans = new LinkedHashMap<>();

/** Map between containing bean names: bean name to Set of bean names that the bean contains. */
private final Map<String, Set<String>> containedBeanMap = new ConcurrentHashMap<>(16);
Expand Down Expand Up @@ -554,7 +554,7 @@ public void destroySingleton(String beanName) {
// Destroy the corresponding DisposableBean instance.
DisposableBean disposableBean;
synchronized (this.disposableBeans) {
disposableBean = (DisposableBean) this.disposableBeans.remove(beanName);
disposableBean = this.disposableBeans.remove(beanName);
}
destroyBean(beanName, disposableBean);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable {

private static final String SHUTDOWN_METHOD_NAME = "shutdown";

private static final Log logger = LogFactory.getLog(DisposableBeanAdapter.class);

private static final Log logger = LogFactory.getLog(DisposableBeanAdapter.class);

private final Object bean;

Expand Down Expand Up @@ -240,7 +240,7 @@ else if (this.destroyMethods != null) {
}
}
else if (this.destroyMethodNames != null) {
for (String destroyMethodName: this.destroyMethodNames) {
for (String destroyMethodName : this.destroyMethodNames) {
Method destroyMethod = determineDestroyMethod(destroyMethodName);
if (destroyMethod != null) {
invokeCustomDestroyMethod(
Expand Down Expand Up @@ -288,7 +288,7 @@ private Method findDestroyMethod(Class<?> clazz, String name) {
*/
private void invokeCustomDestroyMethod(Method destroyMethod) {
int paramCount = destroyMethod.getParameterCount();
final Object[] args = new Object[paramCount];
Object[] args = new Object[paramCount];
if (paramCount == 1) {
args[0] = Boolean.TRUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ ApplicationEventMulticaster getApplicationEventMulticaster() throws IllegalState

@Override
public void setApplicationStartup(ApplicationStartup applicationStartup) {
Assert.notNull(applicationStartup, "applicationStartup must not be null");
Assert.notNull(applicationStartup, "ApplicationStartup must not be null");
this.applicationStartup = applicationStartup;
}

Expand Down Expand Up @@ -946,7 +946,6 @@ protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory b
* onRefresh() method and publishing the
* {@link org.springframework.context.event.ContextRefreshedEvent}.
*/
@SuppressWarnings("deprecation")
protected void finishRefresh() {
// Clear context-level resource caches (such as ASM metadata from scanning).
clearResourceCaches();
Expand Down Expand Up @@ -1047,7 +1046,6 @@ public void close() {
* @see #close()
* @see #registerShutdownHook()
*/
@SuppressWarnings("deprecation")
protected void doClose() {
// Check whether an actual close attempt is necessary...
if (this.active.get() && this.closed.compareAndSet(false, true)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
Expand Down Expand Up @@ -41,6 +41,7 @@ class ImportTests {

private DefaultListableBeanFactory processConfigurationClasses(Class<?>... classes) {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.setAllowBeanDefinitionOverriding(false);
for (Class<?> clazz : classes) {
beanFactory.registerBeanDefinition(clazz.getSimpleName(), new RootBeanDefinition(clazz));
}
Expand All @@ -56,9 +57,10 @@ private void assertBeanDefinitionCount(int expectedCount, Class<?>... classes) {
for (Class<?> clazz : classes) {
beanFactory.getBean(clazz);
}

}

// ------------------------------------------------------------------------

@Test
void testProcessImportsWithAsm() {
int configClasses = 2;
Expand Down Expand Up @@ -158,6 +160,13 @@ void testImportAnnotationWithThreeLevelRecursion() {
assertBeanDefinitionCount(configClasses + beansInClasses, FirstLevel.class);
}

@Test
void testImportAnnotationWithThreeLevelRecursionAndDoubleImport() {
int configClasses = 5;
int beansInClasses = 5;
assertBeanDefinitionCount(configClasses + beansInClasses, FirstLevel.class, FirstLevelPlus.class);
}

// ------------------------------------------------------------------------

@Test
Expand All @@ -167,7 +176,6 @@ void testImportAnnotationWithMultipleArguments() {
assertBeanDefinitionCount((configClasses + beansInClasses), WithMultipleArgumentsToImportAnnotation.class);
}


@Test
void testImportAnnotationWithMultipleArgumentsResultingInOverriddenBeanDefinition() {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
Expand Down Expand Up @@ -245,6 +253,11 @@ TestBean m() {
}
}

@Configuration
@Import(ThirdLevel.class)
static class FirstLevelPlus {
}

@Configuration
@Import({ThirdLevel.class, InitBean.class})
static class SecondLevel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ public MethodParameter clone() {
return new MethodParameter(this);
}


/**
* Create a new MethodParameter for the given method or constructor.
* <p>This is a convenience factory method for scenarios where a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void shouldTranslateTimeoutException() {
@Test
public void shouldNotTranslateUnknownExceptions() {
Exception exception = ConnectionFactoryUtils.convertR2dbcException("", "",
new MyTransientExceptions());
new MyTransientException());
assertThat(exception).isExactlyInstanceOf(UncategorizedR2dbcException.class);
}

Expand Down Expand Up @@ -153,7 +153,7 @@ public void messageGenerationNullMessage() {


@SuppressWarnings("serial")
private static class MyTransientExceptions extends R2dbcException {
private static class MyTransientException extends R2dbcException {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DelegatingConnectionFactoryUnitTests {


@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
void shouldDelegateGetConnection() {
Mono<Connection> connectionMono = Mono.just(connectionMock);
when(delegate.create()).thenReturn((Mono) connectionMono);
Expand All @@ -53,6 +53,7 @@ void shouldDelegateUnwrapWithoutImplementing() {
assertThat(connectionFactory.unwrap()).isSameAs(delegate);
}


static class ExampleConnectionFactory extends DelegatingConnectionFactory {

ExampleConnectionFactory(ConnectionFactory targetConnectionFactory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class R2dbcTransactionManagerUnitTests {

private R2dbcTransactionManager tm;


@BeforeEach
@SuppressWarnings({ "unchecked", "rawtypes" })
void before() {
Expand All @@ -74,6 +75,7 @@ void before() {
tm = new R2dbcTransactionManager(connectionFactoryMock);
}


@Test
void testSimpleTransaction() {
TestTransactionSynchronization sync = new TestTransactionSynchronization(
Expand Down Expand Up @@ -445,8 +447,7 @@ void testPropagationSupportsAndRequiresNew() {
}


private static class TestTransactionSynchronization
implements TransactionSynchronization {
private static class TestTransactionSynchronization implements TransactionSynchronization {

private int status;

Expand Down Expand Up @@ -519,7 +520,6 @@ protected void doAfterCompletion(int status) {
this.afterCompletionCalled = true;
assertThat(status).isEqualTo(this.status);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ void shouldAllocateSameConnection() {

Connection c1 = cf1.block();
Connection c2 = cf2.block();

assertThat(c1).isSameAs(c2);

factory.destroy();
}

Expand All @@ -63,7 +63,6 @@ void shouldApplyAutoCommit() {
.verifyComplete();

factory.setAutoCommit(true);

factory.create().as(StepVerifier::create)
.consumeNextWith(actual -> assertThat(actual.isAutoCommit()).isTrue())
.verifyComplete();
Expand All @@ -75,7 +74,6 @@ void shouldApplyAutoCommit() {
@SuppressWarnings("rawtypes")
void shouldSuppressClose() {
SingleConnectionFactory factory = new SingleConnectionFactory("r2dbc:h2:mem:///foo", true);

Connection connection = factory.create().block();

StepVerifier.create(connection.close()).verifyComplete();
Expand All @@ -85,19 +83,19 @@ void shouldSuppressClose() {
StepVerifier.create(
connection.setTransactionIsolationLevel(IsolationLevel.READ_COMMITTED))
.verifyComplete();

factory.destroy();
}

@Test
void shouldNotSuppressClose() {
SingleConnectionFactory factory = new SingleConnectionFactory("r2dbc:h2:mem:///foo", false);

Connection connection = factory.create().block();

StepVerifier.create(connection.close()).verifyComplete();

StepVerifier.create(connection.setTransactionIsolationLevel(IsolationLevel.READ_COMMITTED))
.verifyError(R2dbcNonTransientResourceException.class);

factory.destroy();
}

Expand All @@ -107,7 +105,6 @@ void releaseConnectionShouldNotCloseConnection() {
ConnectionFactoryMetadata metadata = mock();

SingleConnectionFactory factory = new SingleConnectionFactory(connectionMock, metadata, true);

Connection connection = factory.create().block();

ConnectionFactoryUtils.releaseConnection(connection, factory)
Expand All @@ -125,7 +122,6 @@ void releaseConnectionShouldCloseUnrelatedConnection() {
when(otherConnection.close()).thenReturn(Mono.empty());

SingleConnectionFactory factory = new SingleConnectionFactory(connectionMock, metadata, false);

factory.create().as(StepVerifier::create).expectNextCount(1).verifyComplete();

ConnectionFactoryUtils.releaseConnection(otherConnection, factory)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class TransactionAwareConnectionFactoryProxyUnitTests {

R2dbcTransactionManager tm;


@BeforeEach
@SuppressWarnings({ "rawtypes", "unchecked" })
void before() {
Expand All @@ -63,6 +64,7 @@ void before() {
tm = new R2dbcTransactionManager(connectionFactoryMock);
}


@Test
void createShouldWrapConnection() {
new TransactionAwareConnectionFactoryProxy(connectionFactoryMock).create()
Expand Down
Loading

0 comments on commit 4b8adf2

Please sign in to comment.