Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Dec 29, 2014
1 parent 6f2de28 commit 86b8112
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
Expand Down Expand Up @@ -100,9 +100,10 @@ public static String getTargetBeanName(String originalBeanName) {
/**
* Specify if the {@code beanName} is the name of a bean that references the target
* bean within a scoped proxy.
* @since 4.1.4
*/
public static boolean isScopedTarget(String beanName) {
return beanName.startsWith(TARGET_NAME_PREFIX);
return (beanName != null && beanName.startsWith(TARGET_NAME_PREFIX));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,12 @@ else if (EnumMap.class.equals(mapType)) {
* @param enumType the enum type, never {@code null}
* @return the given type as subtype of {@link Enum}
* @throws IllegalArgumentException if the given type is not a subtype of {@link Enum}
* @since 4.1.4
*/
@SuppressWarnings("rawtypes")
private static Class<? extends Enum> asEnumType(Class<?> enumType) {
Assert.notNull(enumType, "Enum type must not be null");
if (!Enum.class.isAssignableFrom(enumType)) {
throw new IllegalArgumentException(String.format("The supplied type '%s' is not an enum.", enumType.getName()));
throw new IllegalArgumentException("Supplied type is not an enum: " + enumType.getName());
}
return enumType.asSubclass(Enum.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
Expand All @@ -23,10 +23,11 @@
import org.springframework.http.HttpRequest;

/**
* Represents a client-side HTTP request. Created via an implementation of the {@link ClientHttpRequestFactory}.
* Represents a client-side HTTP request.
* Created via an implementation of the {@link ClientHttpRequestFactory}.
*
* <p>A {@code ClientHttpRequest} can be {@linkplain #execute() executed}, getting a
* {@link ClientHttpResponse} which can be read from.
* <p>A {@code ClientHttpRequest} can be {@linkplain #execute() executed},
* receiving a {@link ClientHttpResponse} which can be read from.
*
* @author Arjen Poutsma
* @since 3.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
Expand All @@ -23,10 +23,11 @@
import org.springframework.http.HttpStatus;

/**
* Represents a client-side HTTP response. Obtained via an calling of the {@link ClientHttpRequest#execute()}.
* Represents a client-side HTTP response.
* Obtained via an calling of the {@link ClientHttpRequest#execute()}.
*
* <p>A {@code ClientHttpResponse} must be {@linkplain #close() closed}, typically in a
* {@code finally} block.
* <p>A {@code ClientHttpResponse} must be {@linkplain #close() closed},
* typically in a {@code finally} block.
*
* @author Arjen Poutsma
* @since 3.0
Expand Down Expand Up @@ -55,7 +56,7 @@ public interface ClientHttpResponse extends HttpInputMessage, Closeable {
String getStatusText() throws IOException;

/**
* Closes this response, freeing any resources created.
* Close this response, freeing any resources created.
*/
@Override
void close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void setUp() throws Exception {

// final Template expectedTemplate = new Template();
fc = new FreeMarkerConfigurer();
fc.setTemplateLoaderPaths(new String[] { "classpath:/", "file://" + System.getProperty("java.io.tmpdir") });
fc.setTemplateLoaderPaths("classpath:/", "file://" + System.getProperty("java.io.tmpdir"));
fc.afterPropertiesSet();

wac.getDefaultListableBeanFactory().registerSingleton("freeMarkerConfigurer", fc);
Expand All @@ -86,6 +86,7 @@ public void setUp() throws Exception {
response = new MockHttpServletResponse();
}


@Test
public void testExposeSpringMacroHelpers() throws Exception {
FreeMarkerView fv = new FreeMarkerView() {
Expand Down Expand Up @@ -128,7 +129,8 @@ protected void processTemplate(Template template, SimpleHash model, HttpServletR

try {
fv.render(model, request, response);
} catch (Exception ex) {
}
catch (Exception ex) {
assertTrue(ex instanceof ServletException);
assertTrue(ex.getMessage().contains(FreeMarkerView.SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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.
Expand Down Expand Up @@ -69,7 +69,7 @@ public void testNoFreeMarkerConfig() throws Exception {
}
catch (ApplicationContextException ex) {
// Check there's a helpful error message
assertTrue(ex.getMessage().indexOf("FreeMarkerConfig") != -1);
assertTrue(ex.getMessage().contains("FreeMarkerConfig"));
}
}

Expand All @@ -82,7 +82,7 @@ public void testNoTemplateName() throws Exception {
}
catch (IllegalArgumentException ex) {
// Check there's a helpful error message
assertTrue(ex.getMessage().indexOf("url") != -1);
assertTrue(ex.getMessage().contains("url"));
}
}

Expand All @@ -93,7 +93,7 @@ public void testValidTemplateName() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
MockServletContext sc = new MockServletContext();

Map configs = new HashMap();
Map<String, FreeMarkerConfig> configs = new HashMap<String, FreeMarkerConfig>();
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setConfiguration(new TestConfiguration());
configs.put("configurer", configurer);
Expand All @@ -109,7 +109,7 @@ public void testValidTemplateName() throws Exception {
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
HttpServletResponse response = new MockHttpServletResponse();

Map model = new HashMap();
Map<String, Object> model = new HashMap<String, Object>();
model.put("myattr", "myvalue");
fv.render(model, request, response);

Expand All @@ -123,7 +123,7 @@ public void testKeepExistingContentType() throws Exception {
WebApplicationContext wac = mock(WebApplicationContext.class);
MockServletContext sc = new MockServletContext();

Map configs = new HashMap();
Map<String, FreeMarkerConfig> configs = new HashMap<String, FreeMarkerConfig>();
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setConfiguration(new TestConfiguration());
configs.put("configurer", configurer);
Expand All @@ -140,7 +140,7 @@ public void testKeepExistingContentType() throws Exception {
HttpServletResponse response = new MockHttpServletResponse();
response.setContentType("myContentType");

Map model = new HashMap();
Map<String, Object> model = new HashMap<String, Object>();
model.put("myattr", "myvalue");
fv.render(model, request, response);

Expand Down Expand Up @@ -184,7 +184,7 @@ private class TestConfiguration extends Configuration {
@Override
public Template getTemplate(String name, final Locale locale) throws IOException {
if (name.equals("templateName") || name.equals("prefix_test_suffix")) {
return new Template(name, new StringReader("test")) {
return new Template(name, new StringReader("test"), this) {
@Override
public void process(Object model, Writer writer) throws TemplateException, IOException {
assertEquals(Locale.US, locale);
Expand Down

0 comments on commit 86b8112

Please sign in to comment.