From 0e446b28cdda15a92d8b365bc908c8f4eda055ac Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 22 Aug 2017 16:46:39 +0200 Subject: [PATCH] SONAR-9283 fix dropped support of empty properties in Props --- .../src/main/java/org/sonar/process/Props.java | 6 +----- .../src/test/java/org/sonar/process/PropsTest.java | 10 ++++------ 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/server/sonar-process/src/main/java/org/sonar/process/Props.java b/server/sonar-process/src/main/java/org/sonar/process/Props.java index fd9c896089f..53cb323b365 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/Props.java +++ b/server/sonar-process/src/main/java/org/sonar/process/Props.java @@ -122,10 +122,6 @@ public class Props { if (value == null) { return null; } - String trimmed = value.trim(); - if (trimmed.isEmpty()) { - return null; - } - return trimmed; + return value.trim(); } } diff --git a/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java b/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java index 8c7d21a6567..0a6d4311dba 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/PropsTest.java @@ -52,8 +52,8 @@ public class PropsTest { assertThat(props.value("foo")).isEqualTo("bar"); assertThat(props.value("foo", "default value")).isEqualTo("bar"); - assertThat(props.value("blank")).isNull(); - assertThat(props.value("blank", "default value")).isEqualTo("default value"); + assertThat(props.value("blank")).isEmpty(); + assertThat(props.value("blank", "default value")).isEmpty(); assertThat(props.value("unknown")).isNull(); assertThat(props.value("unknown", "default value")).isEqualTo("default value"); } @@ -80,14 +80,12 @@ public class PropsTest { @Test @UseDataProvider("beforeAndAfterBlanks") - public void nonNullValue_throws_IAE_on_existing_key_with_blank_value(String blankBefore, String blankAfter) { + public void nonNullValue_return_empty_string_IAE_on_existing_key_with_blank_value(String blankBefore, String blankAfter) { Properties p = new Properties(); p.setProperty("blank", blankBefore + blankAfter); Props props = new Props(p); - expectedException.expect(IllegalArgumentException.class); - - props.nonNullValue("blank"); + assertThat(props.nonNullValue("blank")).isEmpty(); } @Test -- 2.39.5