提交 452b124f 编写于 作者: S Sam Brannen

Polish FreeMarker tests and suppress warnings

上级 58c29907
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
......@@ -27,6 +27,7 @@ import freemarker.template.Configuration;
import freemarker.template.SimpleHash;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.junit.Before;
import org.junit.Test;
......@@ -91,6 +92,7 @@ public class FreeMarkerMacroTests {
public void testExposeSpringMacroHelpers() throws Exception {
FreeMarkerView fv = new FreeMarkerView() {
@Override
@SuppressWarnings("rawtypes")
protected void processTemplate(Template template, SimpleHash fmModel, HttpServletResponse response)
throws TemplateException {
Map model = fmModel.toMap();
......
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
......@@ -25,11 +25,9 @@ import java.util.Locale;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import freemarker.ext.servlet.AllHttpScopesHashModel;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.context.ApplicationContextException;
import org.springframework.mock.web.test.MockHttpServletRequest;
......@@ -44,17 +42,27 @@ import org.springframework.web.servlet.view.AbstractView;
import org.springframework.web.servlet.view.InternalResourceView;
import org.springframework.web.servlet.view.RedirectView;
import freemarker.ext.servlet.AllHttpScopesHashModel;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* @author Juergen Hoeller
* @author Sam Brannen
* @since 14.03.2004
*/
public class FreeMarkerViewTests {
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
public void testNoFreeMarkerConfig() throws Exception {
public void noFreeMarkerConfig() throws Exception {
FreeMarkerView fv = new FreeMarkerView();
WebApplicationContext wac = mock(WebApplicationContext.class);
......@@ -62,32 +70,23 @@ public class FreeMarkerViewTests {
given(wac.getServletContext()).willReturn(new MockServletContext());
fv.setUrl("anythingButNull");
try {
fv.setApplicationContext(wac);
fv.afterPropertiesSet();
fail("Should have thrown BeanDefinitionStoreException");
}
catch (ApplicationContextException ex) {
// Check there's a helpful error message
assertTrue(ex.getMessage().contains("FreeMarkerConfig"));
}
exception.expect(ApplicationContextException.class);
exception.expectMessage(containsString("FreeMarkerConfig"));
fv.setApplicationContext(wac);
}
@Test
public void testNoTemplateName() throws Exception {
public void noTemplateName() throws Exception {
FreeMarkerView fv = new FreeMarkerView();
try {
fv.afterPropertiesSet();
fail("Should have thrown IllegalArgumentException");
}
catch (IllegalArgumentException ex) {
// Check there's a helpful error message
assertTrue(ex.getMessage().contains("url"));
}
exception.expect(IllegalArgumentException.class);
exception.expectMessage(containsString("url"));
fv.afterPropertiesSet();
}
@Test
public void testValidTemplateName() throws Exception {
public void validTemplateName() throws Exception {
FreeMarkerView fv = new FreeMarkerView();
WebApplicationContext wac = mock(WebApplicationContext.class);
......@@ -117,7 +116,7 @@ public class FreeMarkerViewTests {
}
@Test
public void testKeepExistingContentType() throws Exception {
public void keepExistingContentType() throws Exception {
FreeMarkerView fv = new FreeMarkerView();
WebApplicationContext wac = mock(WebApplicationContext.class);
......@@ -148,7 +147,7 @@ public class FreeMarkerViewTests {
}
@Test
public void testFreeMarkerViewResolver() throws Exception {
public void freeMarkerViewResolver() throws Exception {
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setConfiguration(new TestConfiguration());
......@@ -181,6 +180,10 @@ public class FreeMarkerViewTests {
private class TestConfiguration extends Configuration {
TestConfiguration() {
super(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
}
@Override
public Template getTemplate(String name, final Locale locale) throws IOException {
if (name.equals("templateName") || name.equals("prefix_test_suffix")) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册