diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index 7f128dfb6a..ba5f83c7e2 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -21,7 +21,7 @@ import org.springframework.util.StringUtils; /** * Configuration properties for Rabbit. - * + * * @author Greg Turnquist * @author Dave Syer */ @@ -110,15 +110,11 @@ public class RabbitProperties { } public void setVirtualHost(String virtualHost) { - if ("".equals(virtualHost) || virtualHost.equals("/")) { - this.virtualHost = "/"; - } else { -// remove all trailing / - while (virtualHost.startsWith("/") && virtualHost.length() > 0) { - virtualHost = virtualHost.substring(1); - } - this.virtualHost = virtualHost; - } + while (virtualHost.startsWith("/") && virtualHost.length() > 0) { + virtualHost = virtualHost.substring(1); + } + this.virtualHost = ("".equals(virtualHost) ? "/" : virtualHost); + } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java index 0be2b868e0..0784020195 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoconfigurationTests.java @@ -16,9 +16,6 @@ package org.springframework.boot.autoconfigure.amqp; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -33,9 +30,12 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + /** * Tests for {@link RabbitAutoConfiguration}. - * + * * @author Greg Turnquist */ public class RabbitAutoconfigurationTests { @@ -74,7 +74,7 @@ public class RabbitAutoconfigurationTests { .getBean(CachingConnectionFactory.class); assertEquals("remote-server", connectionFactory.getHost()); assertEquals(9000, connectionFactory.getPort()); - assertEquals("vhost", connectionFactory.getVirtualHost()); + assertEquals("vhost", connectionFactory.getVirtualHost()); } @Test diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitPropertiesTests.java index dd259f4d9d..ee3fbda3b2 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/amqp/RabbitPropertiesTests.java @@ -16,14 +16,14 @@ package org.springframework.boot.autoconfigure.amqp; +import org.junit.Test; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import org.junit.Test; - /** * Tests for {@link RabbitProperties}. - * + * * @author Dave Syer */ public class RabbitPropertiesTests { @@ -50,28 +50,28 @@ public class RabbitPropertiesTests { assertEquals(9999, this.properties.getPort()); } - @Test - public void testDefaultVirtualHost() { - this.properties.setVirtualHost("/"); - assertEquals("/", this.properties.getVirtualHost()); - } + @Test + public void testDefaultVirtualHost() { + this.properties.setVirtualHost("/"); + assertEquals("/", this.properties.getVirtualHost()); + } - @Test - public void testemptyVirtualHost() { - this.properties.setVirtualHost(""); - assertEquals("/", this.properties.getVirtualHost()); - } + @Test + public void testemptyVirtualHost() { + this.properties.setVirtualHost(""); + assertEquals("/", this.properties.getVirtualHost()); + } - @Test - public void testCustomVirtualHost() { - this.properties.setVirtualHost("myvHost"); - assertEquals("myvHost", this.properties.getVirtualHost()); - } + @Test + public void testCustomVirtualHost() { + this.properties.setVirtualHost("myvHost"); + assertEquals("myvHost", this.properties.getVirtualHost()); + } - @Test - public void testCustomFalsyVirtualHost() { - this.properties.setVirtualHost("/myvHost"); - assertEquals("myvHost", this.properties.getVirtualHost()); - } + @Test + public void testCustomFalsyVirtualHost() { + this.properties.setVirtualHost("/myvHost"); + assertEquals("myvHost", this.properties.getVirtualHost()); + } }