Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
chenpeng_fei
spring-framework
提交
452b124f
S
spring-framework
项目概览
chenpeng_fei
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
452b124f
编写于
9月 28, 2015
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish FreeMarker tests and suppress warnings
上级
58c29907
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
33 addition
and
28 deletion
+33
-28
spring-webmvc/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerMacroTests.java
...ork/web/servlet/view/freemarker/FreeMarkerMacroTests.java
+3
-1
spring-webmvc/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerViewTests.java
...work/web/servlet/view/freemarker/FreeMarkerViewTests.java
+30
-27
未找到文件。
spring-webmvc/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerMacroTests.java
浏览文件 @
452b124f
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
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
();
...
...
spring-webmvc/src/test/java/org/springframework/web/servlet/view/freemarker/FreeMarkerViewTests.java
浏览文件 @
452b124f
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
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
testN
oFreeMarkerConfig
()
throws
Exception
{
public
void
n
oFreeMarkerConfig
()
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
testN
oTemplateName
()
throws
Exception
{
public
void
n
oTemplateName
()
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
testV
alidTemplateName
()
throws
Exception
{
public
void
v
alidTemplateName
()
throws
Exception
{
FreeMarkerView
fv
=
new
FreeMarkerView
();
WebApplicationContext
wac
=
mock
(
WebApplicationContext
.
class
);
...
...
@@ -117,7 +116,7 @@ public class FreeMarkerViewTests {
}
@Test
public
void
testK
eepExistingContentType
()
throws
Exception
{
public
void
k
eepExistingContentType
()
throws
Exception
{
FreeMarkerView
fv
=
new
FreeMarkerView
();
WebApplicationContext
wac
=
mock
(
WebApplicationContext
.
class
);
...
...
@@ -148,7 +147,7 @@ public class FreeMarkerViewTests {
}
@Test
public
void
testF
reeMarkerViewResolver
()
throws
Exception
{
public
void
f
reeMarkerViewResolver
()
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录