Skip to content

Commit a20d7fa

Browse files
committed
Polishing
1 parent be0e0f6 commit a20d7fa

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,6 +43,7 @@ public class StaticMessageSource extends AbstractMessageSource {
4343

4444

4545
@Override
46+
@Nullable
4647
protected String resolveCodeWithoutArguments(String code, Locale locale) {
4748
return this.messages.get(code + '_' + locale.toString());
4849
}

spring-context/src/test/java/org/springframework/context/support/StaticMessageSourceTests.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,7 +62,6 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
6262
@Test
6363
@Override
6464
public void count() {
65-
// These are only checked for current Ctx (not parent ctx)
6665
assertCount(15);
6766
}
6867

@@ -109,8 +108,8 @@ public void getMessageWithMessageAlreadyLookedFor() {
109108

110109
// Now msg better be as expected
111110
assertTrue("2nd search within MsgFormat cache returned expected message for Locale.US",
112-
sac.getMessage("message.format.example1", arguments, Locale.US).indexOf(
113-
"there was \"a disturbance in the Force\" on planet 7.") != -1);
111+
sac.getMessage("message.format.example1", arguments, Locale.US).
112+
contains("there was \"a disturbance in the Force\" on planet 7."));
114113

115114
Object[] newArguments = {
116115
new Integer(8), new Date(System.currentTimeMillis()),
@@ -119,8 +118,8 @@ public void getMessageWithMessageAlreadyLookedFor() {
119118

120119
// Now msg better be as expected even with different args
121120
assertTrue("2nd search within MsgFormat cache with different args returned expected message for Locale.US",
122-
sac.getMessage("message.format.example1", newArguments, Locale.US)
123-
.indexOf("there was \"a disturbance in the Force\" on planet 8.") != -1);
121+
sac.getMessage("message.format.example1", newArguments, Locale.US).
122+
contains("there was \"a disturbance in the Force\" on planet 8."));
124123
}
125124

126125
/**
@@ -142,13 +141,13 @@ public void getMessageWithNoDefaultPassedInAndFoundInMsgCatalog() {
142141
minutes of the time might not be the same.
143142
*/
144143
assertTrue("msg from staticMsgSource for Locale.US substituting args for placeholders is as expected",
145-
sac.getMessage("message.format.example1", arguments, Locale.US)
146-
.indexOf("there was \"a disturbance in the Force\" on planet 7.") != -1);
144+
sac.getMessage("message.format.example1", arguments, Locale.US).
145+
contains("there was \"a disturbance in the Force\" on planet 7."));
147146

148147
// Try with Locale.UK
149148
assertTrue("msg from staticMsgSource for Locale.UK substituting args for placeholders is as expected",
150-
sac.getMessage("message.format.example1", arguments, Locale.UK)
151-
.indexOf("there was \"a disturbance in the Force\" on station number 7.") != -1);
149+
sac.getMessage("message.format.example1", arguments, Locale.UK).
150+
contains("there was \"a disturbance in the Force\" on station number 7."));
152151

153152
// Try with Locale.US - Use a different test msg that requires no args
154153
assertTrue("msg from staticMsgSource for Locale.US that requires no args is as expected",

0 commit comments

Comments
 (0)