From ea18fe58e44bd88c7e01fe56abd9fafcd9fc72b7 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 2 Mar 2017 12:16:28 +0100 Subject: [PATCH] Remove useless checked exception throw clause --- .../mongo/MongoAutoConfiguration.java | 4 +-- .../mongo/MongoClientFactory.java | 8 ++---- .../mongo/MongoClientFactoryTests.java | 25 ++++++++----------- .../mongo/MongoPropertiesTests.java | 4 +-- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java index 2774a3d3c5..d73bac72fa 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.java @@ -16,8 +16,6 @@ package org.springframework.boot.autoconfigure.mongo; -import java.net.UnknownHostException; - import javax.annotation.PreDestroy; import com.mongodb.MongoClient; @@ -68,7 +66,7 @@ public class MongoAutoConfiguration { @Bean @ConditionalOnMissingBean - public MongoClient mongo() throws UnknownHostException { + public MongoClient mongo() { this.mongo = this.factory.createMongoClient(this.options); return this.mongo; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactory.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactory.java index d66f11acbf..8014165350 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactory.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactory.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.mongo; -import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -59,10 +58,8 @@ public class MongoClientFactory { * to an embedded MongoDB instance. * @param options the options * @return the Mongo client - * @throws UnknownHostException if the configured host is unknown */ - public MongoClient createMongoClient(MongoClientOptions options) - throws UnknownHostException { + public MongoClient createMongoClient(MongoClientOptions options) { Integer embeddedPort = getEmbeddedPort(); if (embeddedPort != null) { return createEmbeddedMongoClient(options, embeddedPort); @@ -91,8 +88,7 @@ public class MongoClientFactory { Collections.emptyList(), options); } - private MongoClient createNetworkMongoClient(MongoClientOptions options) - throws UnknownHostException { + private MongoClient createNetworkMongoClient(MongoClientOptions options) { if (hasCustomAddress() || hasCustomCredentials()) { if (this.properties.getUri() != null) { diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java index 4cae1b91fd..c628ee19a4 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoClientFactoryTests.java @@ -16,7 +16,6 @@ package org.springframework.boot.autoconfigure.mongo; -import java.net.UnknownHostException; import java.util.List; import com.mongodb.MongoClient; @@ -52,7 +51,7 @@ public class MongoClientFactoryTests { private MockEnvironment environment = new MockEnvironment(); @Test - public void portCanBeCustomized() throws UnknownHostException { + public void portCanBeCustomized() { MongoProperties properties = new MongoProperties(); properties.setPort(12345); MongoClient client = createMongoClient(properties); @@ -62,7 +61,7 @@ public class MongoClientFactoryTests { } @Test - public void hostCanBeCustomized() throws UnknownHostException { + public void hostCanBeCustomized() { MongoProperties properties = new MongoProperties(); properties.setHost("mongo.example.com"); MongoClient client = createMongoClient(properties); @@ -72,7 +71,7 @@ public class MongoClientFactoryTests { } @Test - public void credentialsCanBeCustomized() throws UnknownHostException { + public void credentialsCanBeCustomized() { MongoProperties properties = new MongoProperties(); properties.setUsername("user"); properties.setPassword("secret".toCharArray()); @@ -82,7 +81,7 @@ public class MongoClientFactoryTests { } @Test - public void databaseCanBeCustomized() throws UnknownHostException { + public void databaseCanBeCustomized() { MongoProperties properties = new MongoProperties(); properties.setDatabase("foo"); properties.setUsername("user"); @@ -93,7 +92,7 @@ public class MongoClientFactoryTests { } @Test - public void authenticationDatabaseCanBeCustomized() throws UnknownHostException { + public void authenticationDatabaseCanBeCustomized() { MongoProperties properties = new MongoProperties(); properties.setAuthenticationDatabase("foo"); properties.setUsername("user"); @@ -104,7 +103,7 @@ public class MongoClientFactoryTests { } @Test - public void uriCanBeCustomized() throws UnknownHostException { + public void uriCanBeCustomized() { MongoProperties properties = new MongoProperties(); properties.setUri("mongodb://user:secret@mongo1.example.com:12345," + "mongo2.example.com:23456/test"); @@ -119,7 +118,7 @@ public class MongoClientFactoryTests { } @Test - public void uriCannotBeSetWithCredentials() throws UnknownHostException { + public void uriCannotBeSetWithCredentials() { MongoProperties properties = new MongoProperties(); properties.setUri("mongodb://127.0.0.1:1234/mydb"); properties.setUsername("user"); @@ -131,7 +130,7 @@ public class MongoClientFactoryTests { } @Test - public void uriCannotBeSetWithHostPort() throws UnknownHostException { + public void uriCannotBeSetWithHostPort() { MongoProperties properties = new MongoProperties(); properties.setUri("mongodb://127.0.0.1:1234/mydb"); properties.setHost("localhost"); @@ -143,7 +142,7 @@ public class MongoClientFactoryTests { } @Test - public void uriIsIgnoredInEmbeddedMode() throws UnknownHostException { + public void uriIsIgnoredInEmbeddedMode() { MongoProperties properties = new MongoProperties(); properties.setUri("mongodb://mongo.example.com:1234/mydb"); this.environment.setProperty("local.mongo.port", "4000"); @@ -153,14 +152,12 @@ public class MongoClientFactoryTests { assertServerAddress(allAddresses.get(0), "localhost", 4000); } - private MongoClient createMongoClient(MongoProperties properties) - throws UnknownHostException { + private MongoClient createMongoClient(MongoProperties properties) { return createMongoClient(properties, null); } private MongoClient createMongoClient(MongoProperties properties, - Environment environment) - throws UnknownHostException { + Environment environment) { return new MongoClientFactory(properties, environment).createMongoClient(null); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java index 504e807f8b..e3b951b430 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/mongo/MongoPropertiesTests.java @@ -16,8 +16,6 @@ package org.springframework.boot.autoconfigure.mongo; -import java.net.UnknownHostException; - import com.mongodb.MongoClient; import com.mongodb.MongoClientOptions; import org.junit.Rule; @@ -56,7 +54,7 @@ public class MongoPropertiesTests { } @Test - public void allMongoClientOptionsCanBeSet() throws UnknownHostException { + public void allMongoClientOptionsCanBeSet() { MongoClientOptions.Builder builder = MongoClientOptions.builder(); builder.alwaysUseMBeans(true); builder.connectionsPerHost(101);