Skip to content

Commit

Permalink
2.2 General Code and API Cleanup
Browse files Browse the repository at this point in the history
- remove redundant `implements`
- remove redundant `throws`
- narrow thrown exceptions
- other 2.2. TODOs
  • Loading branch information
garyrussell authored and artembilan committed Feb 15, 2019
1 parent 00827fc commit b2802b5
Show file tree
Hide file tree
Showing 53 changed files with 255 additions and 310 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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 @@ -190,7 +190,7 @@ public Binding match() {
}
}

private abstract static class AbstractRoutingKeyConfigurer<E extends Exchange> {
private abstract static class AbstractRoutingKeyConfigurer {

protected final DestinationConfigurer destination; // NOSONAR

Expand All @@ -205,7 +205,7 @@ private abstract static class AbstractRoutingKeyConfigurer<E extends Exchange> {
/**
* Topic exchange routing key configurer.
*/
public static final class TopicExchangeRoutingKeyConfigurer extends AbstractRoutingKeyConfigurer<TopicExchange> {
public static final class TopicExchangeRoutingKeyConfigurer extends AbstractRoutingKeyConfigurer {

TopicExchangeRoutingKeyConfigurer(DestinationConfigurer destination, TopicExchange exchange) {
super(destination, exchange.getName());
Expand All @@ -225,7 +225,7 @@ public Binding with(Enum<?> routingKeyEnum) {
/**
* Generic exchange routing key configurer.
*/
public static final class GenericExchangeRoutingKeyConfigurer extends AbstractRoutingKeyConfigurer<TopicExchange> {
public static final class GenericExchangeRoutingKeyConfigurer extends AbstractRoutingKeyConfigurer {

GenericExchangeRoutingKeyConfigurer(DestinationConfigurer destination, Exchange exchange) {
super(destination, exchange.getName());
Expand Down Expand Up @@ -270,7 +270,7 @@ public Binding noargs() {
/**
* Direct exchange routing key configurer.
*/
public static final class DirectExchangeRoutingKeyConfigurer extends AbstractRoutingKeyConfigurer<DirectExchange> {
public static final class DirectExchangeRoutingKeyConfigurer extends AbstractRoutingKeyConfigurer {

DirectExchangeRoutingKeyConfigurer(DestinationConfigurer destination, DirectExchange exchange) {
super(destination, exchange.getName());
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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 All @@ -17,7 +17,6 @@
package org.springframework.amqp.remoting.client;

import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

Expand All @@ -42,8 +41,7 @@
* @see org.springframework.remoting.rmi.RmiServiceExporter
* @see org.springframework.remoting.RemoteAccessException
*/
public class AmqpProxyFactoryBean extends AmqpClientInterceptor implements FactoryBean<Object>, BeanClassLoaderAware,
InitializingBean {
public class AmqpProxyFactoryBean extends AmqpClientInterceptor implements FactoryBean<Object>, InitializingBean {

private Object serviceProxy;

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2019 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 @@ -68,7 +68,7 @@ public abstract class AbstractJackson2MessageConverter extends AbstractMessageCo
@Nullable
private ClassMapper classMapper = null;

protected boolean typeMapperSet; // NOSONAR - TODO private in 2.2
private boolean typeMapperSet;

private ClassLoader classLoader = ClassUtils.getDefaultClassLoader();

Expand Down Expand Up @@ -131,6 +131,16 @@ public Jackson2JavaTypeMapper getJavaTypeMapper() {
return this.javaTypeMapper;
}

/**
* Whether or not an explicit java type mapper has been provided.
* @return false if the default type mapper is being used.
* @since 2.2
* @see #setJavaTypeMapper(Jackson2JavaTypeMapper)
*/
public boolean isTypeMapperSet() {
return this.typeMapperSet;
}

public void setJavaTypeMapper(Jackson2JavaTypeMapper javaTypeMapper) {
Assert.notNull(javaTypeMapper, "'javaTypeMapper' cannot be null");
this.javaTypeMapper = javaTypeMapper;
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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 @@ -38,8 +38,7 @@
* @author Artem Bilan
* @author Gary Russell
*/
public class DefaultJackson2JavaTypeMapper extends AbstractJavaTypeMapper
implements Jackson2JavaTypeMapper, ClassMapper {
public class DefaultJackson2JavaTypeMapper extends AbstractJavaTypeMapper implements Jackson2JavaTypeMapper {

private static final List<String> TRUSTED_PACKAGES =
Arrays.asList(
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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 @@ -167,8 +167,7 @@ private Object asString(Message message, MessageProperties properties) {
}

private Object deserialize(ByteArrayInputStream inputStream) throws IOException {
try {
ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream,
try (ObjectInputStream objectInputStream = new ConfigurableObjectInputStream(inputStream,
this.defaultDeserializerClassLoader) {

@Override
Expand All @@ -179,7 +178,7 @@ protected Class<?> resolveClass(ObjectStreamClass classDesc)
return clazz;
}

};
}) {
return objectInputStream.readObject();
}
catch (ClassNotFoundException ex) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 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 All @@ -16,7 +16,6 @@

package org.springframework.amqp.support.converter;

import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
Expand Down Expand Up @@ -58,7 +57,7 @@ public void addWhiteListPatterns(String... patterns) {
Collections.addAll(this.whiteListPatterns, patterns);
}

protected void checkWhiteList(Class<?> clazz) throws IOException {
protected void checkWhiteList(Class<?> clazz) {
SerializationUtils.checkWhiteList(clazz, this.whiteListPatterns);
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-2019 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 @@ -27,7 +27,7 @@
*/
public abstract class AbstractDeflaterPostProcessor extends AbstractCompressingPostProcessor {

protected int level = Deflater.BEST_SPEED; // NOSONAR - TODO: add getter in 2.2
private int level = Deflater.BEST_SPEED;

public AbstractDeflaterPostProcessor() {
super();
Expand All @@ -46,4 +46,12 @@ public void setLevel(int level) {
this.level = level;
}

/**
* Get the deflater compression level.
* @return the level.
*/
public int getLevel() {
return this.level;
}

}
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-2019 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 @@ -40,7 +40,7 @@ public GZipPostProcessor(boolean autoDecompress) {

@Override
protected OutputStream getCompressorStream(OutputStream zipped) throws IOException {
return new SettableLevelGZIPOutputStream(zipped, this.level);
return new SettableLevelGZIPOutputStream(zipped, getLevel());
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-2019 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,7 +41,7 @@ public ZipPostProcessor(boolean autoDecompress) {

@Override
protected OutputStream getCompressorStream(OutputStream zipped) throws IOException {
ZipOutputStream zipper = new SettableLevelZipOutputStream(zipped, this.level);
ZipOutputStream zipper = new SettableLevelZipOutputStream(zipped, getLevel());
zipper.putNextEntry(new ZipEntry("amqp"));
return zipper;
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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 @@ -27,21 +27,22 @@
* @author Dave Syer
* @author Artem Yakshin
* @author Artem Bilan
* @author Gary Russell
*
*/
public class MessagePropertiesTests {



@Test
public void testReplyTo() throws Exception {
public void testReplyTo() {
MessageProperties properties = new MessageProperties();
properties.setReplyTo("foo/bar");
assertEquals("bar", properties.getReplyToAddress().getRoutingKey());
}

@Test
public void testReplyToNullByDefault() throws Exception {
public void testReplyToNullByDefault() {
MessageProperties properties = new MessageProperties();
assertEquals(null, properties.getReplyTo());
assertEquals(null, properties.getReplyToAddress());
Expand Down
Expand Up @@ -108,7 +108,7 @@ public void testEcho() {
}

@Test
public void testSimulatedTimeout() throws Exception {
public void testSimulatedTimeout() {
try {
this.riggedProxy.simulatedTimeoutMethod("timeout");
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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 @@ -42,7 +42,7 @@ public class AmqpMessageHeaderAccessorTests {
public final ExpectedException thrown = ExpectedException.none();

@Test
public void validateAmqpHeaders() throws Exception {
public void validateAmqpHeaders() {
String correlationId = "correlation-id-1234";
Date timestamp = new Date();

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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 @@ -101,7 +101,7 @@ public void fromClassShouldPopulateWithClassNameByDefault() {
}

@Test
public void shouldUseSpecialNameForClassIfPresent() throws Exception {
public void shouldUseSpecialNameForClassIfPresent() {
classMapper.setIdClassMapping(map("daytrade", SimpleTrade.class));
classMapper.afterPropertiesSet();

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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 @@ -102,7 +102,7 @@ public void fromJavaTypeShouldPopulateWithJavaTypeNameByDefault() {
}

@Test
public void shouldUseSpecialNameForClassIfPresent() throws Exception {
public void shouldUseSpecialNameForClassIfPresent() {
javaTypeMapper.setIdClassMapping(map("daytrade", SimpleTrade.class));

javaTypeMapper.fromJavaType(TypeFactory.defaultInstance().constructType(SimpleTrade.class), properties);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-2019 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 @@ -92,7 +92,7 @@ public TestRabbitTemplate template() throws IOException {
}

@Bean
public ConnectionFactory connectionFactory() throws IOException {
public ConnectionFactory connectionFactory() {
ConnectionFactory factory = mock(ConnectionFactory.class);
Connection connection = mock(Connection.class);
Channel channel = mock(Channel.class);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 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 @@ -757,7 +757,7 @@ public void run() {
* A {@link RabbitFuture} with a return type of {@link Message}.
* @since 1.6
*/
public class RabbitMessageFuture extends RabbitFuture<Message> implements ListenableFuture<Message> {
public class RabbitMessageFuture extends RabbitFuture<Message> {

public RabbitMessageFuture(String correlationId, Message requestMessage) {
super(correlationId, requestMessage);
Expand All @@ -771,7 +771,7 @@ public RabbitMessageFuture(String correlationId, Message requestMessage) {
* @param <C> the type.
* @since 1.6
*/
public class RabbitConverterFuture<C> extends RabbitFuture<C> implements ListenableFuture<C> {
public class RabbitConverterFuture<C> extends RabbitFuture<C> {

private volatile ParameterizedTypeReference<C> returnType;

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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 @@ -553,12 +553,12 @@ private static final class ConnectionBlockedListener implements BlockedListener
}

@Override
public void handleBlocked(String reason) throws IOException {
public void handleBlocked(String reason) {
this.applicationEventPublisher.publishEvent(new ConnectionBlockedEvent(this.connection, reason));
}

@Override
public void handleUnblocked() throws IOException {
public void handleUnblocked() {
this.applicationEventPublisher.publishEvent(new ConnectionUnblockedEvent(this.connection));
}

Expand Down

0 comments on commit b2802b5

Please sign in to comment.