Avoid extra space if condition is empty

Previously, if a builder was created with an empty condition, an extra
space was added before the message. This commit checks for this
particular case and adds a space only when necessary.

Closes gh-8218
This commit is contained in:
Stephane Nicoll
2017-02-07 11:59:49 +01:00
parent a1895336fb
commit e88bda4682
2 changed files with 10 additions and 3 deletions

View File

@@ -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);
}
}

View File

@@ -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)")