From a20d7fa11924a6cd7799e189e2f66232680cb7e4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 13 Nov 2019 23:56:44 +0100 Subject: [PATCH] Polishing --- .../context/support/StaticMessageSource.java | 3 ++- .../support/StaticMessageSourceTests.java | 19 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java index cab8f88aa1..80f511c12f 100644 --- a/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2019 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. @@ -43,6 +43,7 @@ public class StaticMessageSource extends AbstractMessageSource { @Override + @Nullable protected String resolveCodeWithoutArguments(String code, Locale locale) { return this.messages.get(code + '_' + locale.toString()); } diff --git a/spring-context/src/test/java/org/springframework/context/support/StaticMessageSourceTests.java b/spring-context/src/test/java/org/springframework/context/support/StaticMessageSourceTests.java index 4196ca405b..68d0dcf317 100644 --- a/spring-context/src/test/java/org/springframework/context/support/StaticMessageSourceTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/StaticMessageSourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2019 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. @@ -62,7 +62,6 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests { @Test @Override public void count() { - // These are only checked for current Ctx (not parent ctx) assertCount(15); } @@ -109,8 +108,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests { // Now msg better be as expected assertTrue("2nd search within MsgFormat cache returned expected message for Locale.US", - sac.getMessage("message.format.example1", arguments, Locale.US).indexOf( - "there was \"a disturbance in the Force\" on planet 7.") != -1); + sac.getMessage("message.format.example1", arguments, Locale.US). + contains("there was \"a disturbance in the Force\" on planet 7.")); Object[] newArguments = { new Integer(8), new Date(System.currentTimeMillis()), @@ -119,8 +118,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests { // Now msg better be as expected even with different args assertTrue("2nd search within MsgFormat cache with different args returned expected message for Locale.US", - sac.getMessage("message.format.example1", newArguments, Locale.US) - .indexOf("there was \"a disturbance in the Force\" on planet 8.") != -1); + sac.getMessage("message.format.example1", newArguments, Locale.US). + contains("there was \"a disturbance in the Force\" on planet 8.")); } /** @@ -142,13 +141,13 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests { minutes of the time might not be the same. */ assertTrue("msg from staticMsgSource for Locale.US substituting args for placeholders is as expected", - sac.getMessage("message.format.example1", arguments, Locale.US) - .indexOf("there was \"a disturbance in the Force\" on planet 7.") != -1); + sac.getMessage("message.format.example1", arguments, Locale.US). + contains("there was \"a disturbance in the Force\" on planet 7.")); // Try with Locale.UK assertTrue("msg from staticMsgSource for Locale.UK substituting args for placeholders is as expected", - sac.getMessage("message.format.example1", arguments, Locale.UK) - .indexOf("there was \"a disturbance in the Force\" on station number 7.") != -1); + sac.getMessage("message.format.example1", arguments, Locale.UK). + contains("there was \"a disturbance in the Force\" on station number 7.")); // Try with Locale.US - Use a different test msg that requires no args assertTrue("msg from staticMsgSource for Locale.US that requires no args is as expected",