Skip to content

Commit f09e252

Browse files
committed
Polishing
1 parent f3b8d71 commit f09e252

File tree

9 files changed

+109
-88
lines changed

9 files changed

+109
-88
lines changed

spring-context/src/test/java/org/springframework/scripting/bsh/BshScriptFactoryTests.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.scripting.bsh;
1818

19+
import java.io.IOException;
1920
import java.util.Arrays;
2021
import java.util.Collection;
2122

@@ -47,7 +48,7 @@
4748
public class BshScriptFactoryTests {
4849

4950
@Test
50-
public void staticScript() throws Exception {
51+
public void staticScript() {
5152
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
5253

5354
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Calculator.class)).contains("calculator"));
@@ -75,7 +76,7 @@ public void staticScript() throws Exception {
7576
}
7677

7778
@Test
78-
public void staticScriptWithNullReturnValue() throws Exception {
79+
public void staticScriptWithNullReturnValue() {
7980
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
8081
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfig"));
8182

@@ -86,7 +87,7 @@ public void staticScriptWithNullReturnValue() throws Exception {
8687
}
8788

8889
@Test
89-
public void staticScriptWithTwoInterfacesSpecified() throws Exception {
90+
public void staticScriptWithTwoInterfacesSpecified() {
9091
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
9192
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfigExtra"));
9293

@@ -100,7 +101,7 @@ public void staticScriptWithTwoInterfacesSpecified() throws Exception {
100101
}
101102

102103
@Test
103-
public void staticWithScriptReturningInstance() throws Exception {
104+
public void staticWithScriptReturningInstance() {
104105
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
105106
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstance"));
106107

@@ -114,7 +115,7 @@ public void staticWithScriptReturningInstance() throws Exception {
114115
}
115116

116117
@Test
117-
public void staticScriptImplementingInterface() throws Exception {
118+
public void staticScriptImplementingInterface() {
118119
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
119120
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerImpl"));
120121

@@ -128,7 +129,7 @@ public void staticScriptImplementingInterface() throws Exception {
128129
}
129130

130131
@Test
131-
public void staticPrototypeScript() throws Exception {
132+
public void staticPrototypeScript() {
132133
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
133134
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
134135
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
@@ -147,7 +148,7 @@ public void staticPrototypeScript() throws Exception {
147148
}
148149

149150
@Test
150-
public void nonStaticScript() throws Exception {
151+
public void nonStaticScript() {
151152
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
152153
Messenger messenger = (Messenger) ctx.getBean("messenger");
153154

@@ -165,7 +166,7 @@ public void nonStaticScript() throws Exception {
165166
}
166167

167168
@Test
168-
public void nonStaticPrototypeScript() throws Exception {
169+
public void nonStaticPrototypeScript() {
169170
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
170171
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
171172
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
@@ -189,7 +190,7 @@ public void nonStaticPrototypeScript() throws Exception {
189190
}
190191

191192
@Test
192-
public void scriptCompilationException() throws Exception {
193+
public void scriptCompilationException() {
193194
try {
194195
new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml");
195196
fail("Must throw exception for broken script file");
@@ -200,7 +201,7 @@ public void scriptCompilationException() throws Exception {
200201
}
201202

202203
@Test
203-
public void scriptThatCompilesButIsJustPlainBad() throws Exception {
204+
public void scriptThatCompilesButIsJustPlainBad() throws IOException {
204205
ScriptSource script = mock(ScriptSource.class);
205206
final String badScript = "String getMessage() { throw new IllegalArgumentException(); }";
206207
given(script.getScriptAsString()).willReturn(badScript);
@@ -217,7 +218,7 @@ public void scriptThatCompilesButIsJustPlainBad() throws Exception {
217218
}
218219

219220
@Test
220-
public void ctorWithNullScriptSourceLocator() throws Exception {
221+
public void ctorWithNullScriptSourceLocator() {
221222
try {
222223
new BshScriptFactory(null, Messenger.class);
223224
fail("Must have thrown exception by this point.");
@@ -227,27 +228,27 @@ public void ctorWithNullScriptSourceLocator() throws Exception {
227228
}
228229

229230
@Test
230-
public void ctorWithEmptyScriptSourceLocator() throws Exception {
231+
public void ctorWithEmptyScriptSourceLocator() {
231232
try {
232-
new BshScriptFactory("", new Class<?>[] {Messenger.class});
233+
new BshScriptFactory("", Messenger.class);
233234
fail("Must have thrown exception by this point.");
234235
}
235236
catch (IllegalArgumentException expected) {
236237
}
237238
}
238239

239240
@Test
240-
public void ctorWithWhitespacedScriptSourceLocator() throws Exception {
241+
public void ctorWithWhitespacedScriptSourceLocator() {
241242
try {
242-
new BshScriptFactory("\n ", new Class<?>[] {Messenger.class});
243+
new BshScriptFactory("\n ", Messenger.class);
243244
fail("Must have thrown exception by this point.");
244245
}
245246
catch (IllegalArgumentException expected) {
246247
}
247248
}
248249

249250
@Test
250-
public void resourceScriptFromTag() throws Exception {
251+
public void resourceScriptFromTag() {
251252
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
252253
TestBean testBean = (TestBean) ctx.getBean("testBean");
253254

@@ -286,7 +287,7 @@ public void resourceScriptFromTag() throws Exception {
286287
}
287288

288289
@Test
289-
public void prototypeScriptFromTag() throws Exception {
290+
public void prototypeScriptFromTag() {
290291
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
291292
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
292293
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
@@ -302,23 +303,23 @@ public void prototypeScriptFromTag() throws Exception {
302303
}
303304

304305
@Test
305-
public void inlineScriptFromTag() throws Exception {
306+
public void inlineScriptFromTag() {
306307
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
307308
Calculator calculator = (Calculator) ctx.getBean("calculator");
308309
assertNotNull(calculator);
309310
assertFalse(calculator instanceof Refreshable);
310311
}
311312

312313
@Test
313-
public void refreshableFromTag() throws Exception {
314+
public void refreshableFromTag() {
314315
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
315316
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
316317
assertEquals("Hello World!", messenger.getMessage());
317318
assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
318319
}
319320

320321
@Test
321-
public void applicationEventListener() throws Exception {
322+
public void applicationEventListener() {
322323
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
323324
Messenger eventListener = (Messenger) ctx.getBean("eventListener");
324325
ctx.publishEvent(new MyEvent(ctx));

spring-context/src/test/resources/org/springframework/scripting/bsh/bsh-with-xsd.xml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<beans xmlns="http://www.springframework.org/schema/beans"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xmlns:lang="http://www.springframework.org/schema/lang"
5-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
6-
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:lang="http://www.springframework.org/schema/lang"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
76
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd">
87

98
<lang:bsh id="messenger" script-source="classpath:org/springframework/scripting/bsh/Messenger.bsh"
@@ -29,7 +28,7 @@
2928
</lang:bsh>
3029

3130
<lang:bsh id="messengerByType" script-source="classpath:org/springframework/scripting/bsh/MessengerImpl.bsh"
32-
autowire="byType" dependency-check="objects" init-method="init" destroy-method="destroy">
31+
autowire="byType" init-method="init" destroy-method="destroy">
3332
</lang:bsh>
3433

3534
<lang:bsh id="messengerByName" script-source="classpath:org/springframework/scripting/bsh/MessengerImpl.bsh"
@@ -52,12 +51,12 @@
5251
<lang:property name="message" value="Hello World!"/>
5352
</lang:bsh>
5453

55-
<lang:bsh id="eventListener" script-interfaces="org.springframework.context.ApplicationListener,org.springframework.scripting.Messenger" >
56-
<lang:inline-script><![CDATA[
57-
int count;
58-
void onApplicationEvent (org.springframework.context.ApplicationEvent event) { count++; System.out.println(event); }
59-
String getMessage() { return "count=" + count; }
60-
]]></lang:inline-script>
61-
</lang:bsh>
54+
<lang:bsh id="eventListener" script-interfaces="org.springframework.context.ApplicationListener,org.springframework.scripting.Messenger" >
55+
<lang:inline-script><![CDATA[
56+
int count;
57+
void onApplicationEvent (org.springframework.context.ApplicationEvent event) { count++; System.out.println(event); }
58+
String getMessage() { return "count=" + count; }
59+
]]></lang:inline-script>
60+
</lang:bsh>
6261

6362
</beans>

spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java

Lines changed: 20 additions & 26 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-2017 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.
@@ -26,12 +26,12 @@
2626
import org.springframework.util.ClassUtils;
2727

2828
/**
29-
* A specialization of {@link GenericConversionService} configured by default with
30-
* converters appropriate for most environments.
29+
* A specialization of {@link GenericConversionService} configured by default
30+
* with converters appropriate for most environments.
3131
*
3232
* <p>Designed for direct instantiation but also exposes the static
33-
* {@link #addDefaultConverters(ConverterRegistry)} utility method for ad hoc use against any
34-
* {@code ConverterRegistry} instance.
33+
* {@link #addDefaultConverters(ConverterRegistry)} utility method for ad-hoc
34+
* use against any {@code ConverterRegistry} instance.
3535
*
3636
* @author Chris Beams
3737
* @author Juergen Hoeller
@@ -55,6 +55,15 @@ public class DefaultConversionService extends GenericConversionService {
5555
private static volatile DefaultConversionService sharedInstance;
5656

5757

58+
/**
59+
* Create a new {@code DefaultConversionService} with the set of
60+
* {@linkplain DefaultConversionService#addDefaultConverters(ConverterRegistry) default converters}.
61+
*/
62+
public DefaultConversionService() {
63+
addDefaultConverters(this);
64+
}
65+
66+
5867
/**
5968
* Return a shared default {@code ConversionService} instance,
6069
* lazily building it once needed.
@@ -77,22 +86,10 @@ public static ConversionService getSharedInstance() {
7786
return sharedInstance;
7887
}
7988

80-
81-
/**
82-
* Create a new {@code DefaultConversionService} with the set of
83-
* {@linkplain DefaultConversionService#addDefaultConverters(ConverterRegistry) default converters}.
84-
*/
85-
public DefaultConversionService() {
86-
addDefaultConverters(this);
87-
}
88-
89-
90-
// static utility methods
91-
9289
/**
9390
* Add converters appropriate for most environments.
94-
* @param converterRegistry the registry of converters to add to (must also be castable to ConversionService,
95-
* e.g. being a {@link ConfigurableConversionService})
91+
* @param converterRegistry the registry of converters to add to
92+
* (must also be castable to ConversionService, e.g. being a {@link ConfigurableConversionService})
9693
* @throws ClassCastException if the given ConverterRegistry could not be cast to a ConversionService
9794
*/
9895
public static void addDefaultConverters(ConverterRegistry converterRegistry) {
@@ -113,9 +110,9 @@ public static void addDefaultConverters(ConverterRegistry converterRegistry) {
113110
}
114111

115112
/**
116-
* Add collection converters.
117-
* @param converterRegistry the registry of converters to add to (must also be castable to ConversionService,
118-
* e.g. being a {@link ConfigurableConversionService})
113+
* Add common collection converters.
114+
* @param converterRegistry the registry of converters to add to
115+
* (must also be castable to ConversionService, e.g. being a {@link ConfigurableConversionService})
119116
* @throws ClassCastException if the given ConverterRegistry could not be cast to a ConversionService
120117
* @since 4.2.3
121118
*/
@@ -146,9 +143,6 @@ public static void addCollectionConverters(ConverterRegistry converterRegistry)
146143
}
147144
}
148145

149-
150-
// internal helpers
151-
152146
private static void addScalarConverters(ConverterRegistry converterRegistry) {
153147
converterRegistry.addConverterFactory(new NumberToNumberConverterFactory());
154148

@@ -166,7 +160,7 @@ private static void addScalarConverters(ConverterRegistry converterRegistry) {
166160

167161
converterRegistry.addConverterFactory(new StringToEnumConverterFactory());
168162
converterRegistry.addConverter(new EnumToStringConverter((ConversionService) converterRegistry));
169-
163+
170164
converterRegistry.addConverterFactory(new IntegerToEnumConverterFactory());
171165
converterRegistry.addConverter(new EnumToIntegerConverter((ConversionService) converterRegistry));
172166

spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMvcRequestBuilders.java

Lines changed: 2 additions & 1 deletion
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-2017 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.
@@ -222,6 +222,7 @@ public static MockMultipartHttpServletRequestBuilder fileUpload(URI uri) {
222222
return new MockMultipartHttpServletRequestBuilder(uri);
223223
}
224224

225+
225226
/**
226227
* Create a {@link RequestBuilder} for an async dispatch from the
227228
* {@link MvcResult} of the request that started async processing.

spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,10 @@ public FormHttpMessageConverter() {
104104
this.supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
105105
this.supportedMediaTypes.add(MediaType.MULTIPART_FORM_DATA);
106106

107-
this.partConverters.add(new ByteArrayHttpMessageConverter());
108107
StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
109-
stringHttpMessageConverter.setWriteAcceptCharset(false);
108+
stringHttpMessageConverter.setWriteAcceptCharset(false); // see SPR-7316
109+
110+
this.partConverters.add(new ByteArrayHttpMessageConverter());
110111
this.partConverters.add(stringHttpMessageConverter);
111112
this.partConverters.add(new ResourceHttpMessageConverter());
112113

spring-web/src/main/java/org/springframework/http/converter/support/AllEncompassingFormHttpMessageConverter.java

Lines changed: 11 additions & 6 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-2017 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.
@@ -37,17 +37,22 @@
3737
public class AllEncompassingFormHttpMessageConverter extends FormHttpMessageConverter {
3838

3939
private static final boolean jaxb2Present =
40-
ClassUtils.isPresent("javax.xml.bind.Binder", AllEncompassingFormHttpMessageConverter.class.getClassLoader());
40+
ClassUtils.isPresent("javax.xml.bind.Binder",
41+
AllEncompassingFormHttpMessageConverter.class.getClassLoader());
4142

4243
private static final boolean jackson2Present =
43-
ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", AllEncompassingFormHttpMessageConverter.class.getClassLoader()) &&
44-
ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", AllEncompassingFormHttpMessageConverter.class.getClassLoader());
44+
ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper",
45+
AllEncompassingFormHttpMessageConverter.class.getClassLoader()) &&
46+
ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator",
47+
AllEncompassingFormHttpMessageConverter.class.getClassLoader());
4548

4649
private static final boolean jackson2XmlPresent =
47-
ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper", AllEncompassingFormHttpMessageConverter.class.getClassLoader());
50+
ClassUtils.isPresent("com.fasterxml.jackson.dataformat.xml.XmlMapper",
51+
AllEncompassingFormHttpMessageConverter.class.getClassLoader());
4852

4953
private static final boolean gsonPresent =
50-
ClassUtils.isPresent("com.google.gson.Gson", AllEncompassingFormHttpMessageConverter.class.getClassLoader());
54+
ClassUtils.isPresent("com.google.gson.Gson",
55+
AllEncompassingFormHttpMessageConverter.class.getClassLoader());
5156

5257

5358
public AllEncompassingFormHttpMessageConverter() {

0 commit comments

Comments
 (0)