diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionMessage.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionMessage.java index 0b45d2f629..43ee2251de 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionMessage.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/condition/ConditionMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -302,7 +302,8 @@ public final class ConditionMessage { return new ConditionMessage(ConditionMessage.this, this.condition); } return new ConditionMessage(ConditionMessage.this, - this.condition + " " + reason); + this.condition + (StringUtils.isEmpty(this.condition) ? "" : " ") + + reason); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionMessageTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionMessageTests.java index d90669143b..fec1496fff 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionMessageTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionMessageTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -117,6 +117,12 @@ public class ConditionMessageTests { assertThat(message.toString()).isEqualTo("@Test OK"); } + @Test + public void forConditionShouldNotAddExtraSpaceWithEmptyCondition() throws Exception { + ConditionMessage message = ConditionMessage.forCondition("").because("OK"); + assertThat(message.toString()).isEqualTo("OK"); + } + @Test public void forConditionWhenClassShouldIncludeCondition() throws Exception { ConditionMessage message = ConditionMessage.forCondition(Test.class, "(a=b)")