From c48cd5c8db6b2c12630b78d31e4979e53be8015b Mon Sep 17 00:00:00 2001 From: David Sowerby Date: Thu, 9 Jun 2016 16:55:39 +0100 Subject: [PATCH] =?UTF-8?q?Revert=20"Fixed=20MessageFormat=20=20which=20is?= =?UTF-8?q?=20not=20working=20when=20the=20same=20argument=20is=20r?= =?UTF-8?q?=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/uk/q3c/util/MessageFormat.java | 19 +++++++++---------- .../java/uk/q3c/util/MessageFormatTest.java | 16 ---------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/main/java/uk/q3c/util/MessageFormat.java b/src/main/java/uk/q3c/util/MessageFormat.java index 12070c67a..67593b6e1 100644 --- a/src/main/java/uk/q3c/util/MessageFormat.java +++ b/src/main/java/uk/q3c/util/MessageFormat.java @@ -115,17 +115,16 @@ private static String scanForParameters(String pattern, List parameters } private static Object[] sortArguments(List parameters, Object[] arguments, String pattern) { - try { - List sortedArguments = new ArrayList<>(); - for (Integer i : parameters) { - sortedArguments.add(arguments[i]); - } - return sortedArguments.toArray(); - } catch (IndexOutOfBoundsException e) { - Object[] args = new Object[] { parameters.size(), arguments.length, pattern }; - log.warn("Message pattern and arguments do not match, there are {} parameters in the pattern, " - + "and {} arguments. The pattern is: '{}'", args); + if (parameters.size() != arguments.length) { + Object[] args = new Object[]{parameters.size(), arguments.length, pattern}; + log.warn("Message pattern and arguments do not match, there are {} parameters in the pattern, " + + "and {} arguments. The pattern is: '{}'", args); throw new RuntimeException(); } + List sortedArguments = new ArrayList<>(); + for (Integer i : parameters) { + sortedArguments.add(arguments[i]); + } + return sortedArguments.toArray(); } } diff --git a/src/test/java/uk/q3c/util/MessageFormatTest.java b/src/test/java/uk/q3c/util/MessageFormatTest.java index 139d328dc..ec7b9c8cf 100644 --- a/src/test/java/uk/q3c/util/MessageFormatTest.java +++ b/src/test/java/uk/q3c/util/MessageFormatTest.java @@ -16,9 +16,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.util.ArrayList; -import java.util.List; - public class MessageFormatTest { @Test public void formatValid() { @@ -32,20 +29,7 @@ public void formatValid() { assertThat(result).isEqualTo("This is a simple pattern where the parameters can be in any order"); } - - @Test - public void formatValidRepeatedArgument() { - - // given - String pattern = "This is a {0} pattern where the same argument is {0}"; - Object[] arguments = new Object[]{"repeated"}; - // when - String result = MessageFormat.format(pattern, arguments); - // then - assertThat(result).isEqualTo("This is a repeated pattern where the same argument is repeated"); - } - @Test public void formatValidContiguous() {