Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
f4f508d8
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
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,体验更适合开发者的 AI 搜索 >>
提交
f4f508d8
编写于
7月 14, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revisit date-time tests for compatibility with JDK 9 build 72
Issue: SPR-13232
上级
48f330dd
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
128 addition
and
201 deletion
+128
-201
spring-context/src/test/java/org/springframework/format/datetime/DateFormatterTests.java
...g/springframework/format/datetime/DateFormatterTests.java
+6
-7
spring-context/src/test/java/org/springframework/format/datetime/DateFormattingTests.java
.../springframework/format/datetime/DateFormattingTests.java
+48
-71
spring-context/src/test/java/org/springframework/format/datetime/joda/DateTimeFormatterFactoryTests.java
...k/format/datetime/joda/DateTimeFormatterFactoryTests.java
+4
-2
spring-context/src/test/java/org/springframework/format/datetime/joda/JodaTimeFormattingTests.java
...amework/format/datetime/joda/JodaTimeFormattingTests.java
+24
-81
spring-context/src/test/java/org/springframework/format/datetime/standard/DateTimeFormatterFactoryTests.java
...rmat/datetime/standard/DateTimeFormatterFactoryTests.java
+4
-2
spring-context/src/test/java/org/springframework/format/datetime/standard/DateTimeFormattingTests.java
...ork/format/datetime/standard/DateTimeFormattingTests.java
+21
-14
spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceFactoryBeanTests.java
.../support/FormattingConversionServiceFactoryBeanTests.java
+15
-14
spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java
.../test/java/org/springframework/http/HttpHeadersTests.java
+4
-9
spring-web/src/test/java/org/springframework/http/converter/json/GsonFactoryBeanTests.java
...ngframework/http/converter/json/GsonFactoryBeanTests.java
+2
-1
未找到文件。
spring-context/src/test/java/org/springframework/format/datetime/DateFormatterTests.java
浏览文件 @
f4f508d8
...
...
@@ -149,7 +149,7 @@ public class DateFormatterTests {
@Test
public
void
shouldSupportJodaStylePatterns
()
throws
Exception
{
String
[]
chars
=
{
"S"
,
"M"
,
"
L"
,
"F"
,
"
-"
};
String
[]
chars
=
{
"S"
,
"M"
,
"-"
};
for
(
String
d
:
chars
)
{
for
(
String
t
:
chars
)
{
String
style
=
d
+
t
;
...
...
@@ -157,7 +157,8 @@ public class DateFormatterTests {
Date
date
=
getDate
(
2009
,
Calendar
.
JUNE
,
10
,
14
,
23
,
0
,
0
);
if
(
t
.
equals
(
"-"
))
{
date
=
getDate
(
2009
,
Calendar
.
JUNE
,
10
);
}
else
if
(
d
.
equals
(
"-"
))
{
}
else
if
(
d
.
equals
(
"-"
))
{
date
=
getDate
(
1970
,
Calendar
.
JANUARY
,
1
,
14
,
23
,
0
,
0
);
}
testJodaStylePatterns
(
style
,
Locale
.
US
,
date
);
...
...
@@ -166,13 +167,11 @@ public class DateFormatterTests {
}
}
private
void
testJodaStylePatterns
(
String
style
,
Locale
locale
,
Date
date
)
throws
Exception
{
private
void
testJodaStylePatterns
(
String
style
,
Locale
locale
,
Date
date
)
throws
Exception
{
DateFormatter
formatter
=
new
DateFormatter
();
formatter
.
setTimeZone
(
UTC
);
formatter
.
setStylePattern
(
style
);
DateTimeFormatter
jodaFormatter
=
DateTimeFormat
.
forStyle
(
style
).
withLocale
(
locale
).
withZone
(
DateTimeZone
.
UTC
);
DateTimeFormatter
jodaFormatter
=
DateTimeFormat
.
forStyle
(
style
).
withLocale
(
locale
).
withZone
(
DateTimeZone
.
UTC
);
String
jodaPrinted
=
jodaFormatter
.
print
(
date
.
getTime
());
assertThat
(
"Unable to print style pattern "
+
style
,
formatter
.
print
(
date
,
locale
),
is
(
equalTo
(
jodaPrinted
)));
...
...
@@ -181,7 +180,7 @@ public class DateFormatterTests {
}
@Test
public
void
shouldThrowOnUnsupportStylePattern
()
throws
Exception
{
public
void
shouldThrowOnUnsupport
ed
StylePattern
()
throws
Exception
{
DateFormatter
formatter
=
new
DateFormatter
();
formatter
.
setStylePattern
(
"OO"
);
thown
.
expect
(
IllegalStateException
.
class
);
...
...
spring-context/src/test/java/org/springframework/format/datetime/DateFormattingTests.java
浏览文件 @
f4f508d8
...
...
@@ -76,20 +76,30 @@ public class DateFormattingTests {
@Test
public
void
testBind
Date
()
{
public
void
testBind
Long
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"
date"
,
"10/31/09 12:00 PM
"
);
propertyValues
.
add
(
"
millis"
,
"1256961600
"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"1
0/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"date
"
));
assertEquals
(
"1
256961600"
,
binder
.
getBindingResult
().
getFieldValue
(
"millis
"
));
}
@Test
public
void
testBind
DateArray
()
{
public
void
testBind
LongAnnotated
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"
date"
,
new
String
[]
{
"10/31/09 12:00 PM"
}
);
propertyValues
.
add
(
"
millisAnnotated"
,
"10/31/09"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09"
,
binder
.
getBindingResult
().
getFieldValue
(
"millisAnnotated"
));
}
@Test
public
void
testBindCalendarAnnotated
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"calendarAnnotated"
,
"10/31/09"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09"
,
binder
.
getBindingResult
().
getFieldValue
(
"calendarAnnotated"
));
}
@Test
...
...
@@ -101,6 +111,14 @@ public class DateFormattingTests {
assertEquals
(
"10/31/09"
,
binder
.
getBindingResult
().
getFieldValue
(
"dateAnnotated"
));
}
@Test
public
void
testBindDateArray
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"dateAnnotated"
,
new
String
[]{
"10/31/09 12:00 PM"
});
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
}
@Test
public
void
testBindDateAnnotatedWithError
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
...
...
@@ -122,39 +140,12 @@ public class DateFormattingTests {
}
@Test
public
void
testBindCalendar
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"calendar"
,
"10/31/09 12:00 PM"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"calendar"
));
}
@Test
public
void
testBindCalendarAnnotated
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"calendarAnnotated"
,
"10/31/09"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09"
,
binder
.
getBindingResult
().
getFieldValue
(
"calendarAnnotated"
));
}
@Test
public
void
testBindLong
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"millis"
,
"1256961600"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"1256961600"
,
binder
.
getBindingResult
().
getFieldValue
(
"millis"
));
}
@Test
public
void
testBindLongAnnotated
()
{
public
void
testBindDateAnnotatedPattern
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"
millisAnnotated"
,
"10/31/09
"
);
propertyValues
.
add
(
"
dateAnnotatedPattern"
,
"10/31/09 1:05
"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09
"
,
binder
.
getBindingResult
().
getFieldValue
(
"millisAnnotated
"
));
assertEquals
(
"10/31/09
1:05"
,
binder
.
getBindingResult
().
getFieldValue
(
"dateAnnotatedPattern
"
));
}
@Test
...
...
@@ -239,23 +230,17 @@ public class DateFormattingTests {
@SuppressWarnings
(
"unused"
)
private
static
class
SimpleDateBean
{
@DateTimeFormat
private
Date
date
;
@DateTimeFormat
(
style
=
"S-"
)
private
Date
dateAnnotated
;
private
Long
millis
;
@DateTimeFormat
private
Calendar
calendar
;
private
Long
millisAnnotated
;
@DateTimeFormat
(
style
=
"S-"
)
private
Calendar
calendarAnnotated
;
private
Long
millis
;
private
Long
millisAnnotated
;
@DateTimeFormat
(
style
=
"S-"
)
private
Date
dateAnnotated
;
@DateTimeFormat
(
pattern
=
"M/d/yy h:mm
a
"
)
@DateTimeFormat
(
pattern
=
"M/d/yy h:mm"
)
private
Date
dateAnnotatedPattern
;
@DateTimeFormat
(
iso
=
ISO
.
DATE
)
...
...
@@ -269,28 +254,21 @@ public class DateFormattingTests {
private
final
List
<
SimpleDateBean
>
children
=
new
ArrayList
<
SimpleDateBean
>();
public
Date
getDate
()
{
return
date
;
}
public
void
setDate
(
Date
date
)
{
this
.
date
=
date
;
}
public
Date
getDateAnnotated
()
{
return
dateAnnotated
;
public
Long
getMillis
()
{
return
millis
;
}
public
void
set
DateAnnotated
(
Date
dateAnnotated
)
{
this
.
dateAnnotated
=
dateAnnotated
;
public
void
set
Millis
(
Long
millis
)
{
this
.
millis
=
millis
;
}
public
Calendar
getCalendar
()
{
return
calendar
;
@DateTimeFormat
(
style
=
"S-"
)
public
Long
getMillisAnnotated
()
{
return
millisAnnotated
;
}
public
void
set
Calendar
(
Calendar
calendar
)
{
this
.
calendar
=
calendar
;
public
void
set
MillisAnnotated
(
@DateTimeFormat
(
style
=
"S-"
)
Long
millisAnnotated
)
{
this
.
millisAnnotated
=
millisAnnotated
;
}
public
Calendar
getCalendarAnnotated
()
{
...
...
@@ -301,21 +279,20 @@ public class DateFormattingTests {
this
.
calendarAnnotated
=
calendarAnnotated
;
}
public
Long
getMillis
()
{
return
millis
;
public
Date
getDateAnnotated
()
{
return
dateAnnotated
;
}
public
void
set
Millis
(
Long
millis
)
{
this
.
millis
=
millis
;
public
void
set
DateAnnotated
(
Date
dateAnnotated
)
{
this
.
dateAnnotated
=
dateAnnotated
;
}
@DateTimeFormat
(
style
=
"S-"
)
public
Long
getMillisAnnotated
()
{
return
millisAnnotated
;
public
Date
getDateAnnotatedPattern
()
{
return
dateAnnotatedPattern
;
}
public
void
set
MillisAnnotated
(
@DateTimeFormat
(
style
=
"S-"
)
Long
millisAnnotated
)
{
this
.
millisAnnotated
=
millisAnnotated
;
public
void
set
DateAnnotatedPattern
(
Date
dateAnnotatedPattern
)
{
this
.
dateAnnotatedPattern
=
dateAnnotatedPattern
;
}
public
Date
getIsoDate
()
{
...
...
spring-context/src/test/java/org/springframework/format/datetime/joda/DateTimeFormatterFactoryTests.java
浏览文件 @
f4f508d8
/*
* Copyright 2002-201
2
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.
...
...
@@ -77,7 +77,9 @@ public class DateTimeFormatterFactoryTests {
@Test
public
void
createDateTimeFormatterInOrderOfPropertyPriority
()
throws
Exception
{
factory
.
setStyle
(
"SS"
);
assertThat
(
applyLocale
(
factory
.
createDateTimeFormatter
()).
print
(
dateTime
),
is
(
"10/21/09 12:10 PM"
));
String
value
=
applyLocale
(
factory
.
createDateTimeFormatter
()).
print
(
dateTime
);
assertTrue
(
value
.
startsWith
(
"10/21/09"
));
assertTrue
(
value
.
endsWith
(
"12:10 PM"
));
factory
.
setIso
(
ISO
.
DATE
);
assertThat
(
applyLocale
(
factory
.
createDateTimeFormatter
()).
print
(
dateTime
),
is
(
"2009-10-21"
));
...
...
spring-context/src/test/java/org/springframework/format/datetime/joda/JodaTimeFormattingTests.java
浏览文件 @
f4f508d8
/*
* Copyright 2002-201
3
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.
...
...
@@ -28,7 +28,6 @@ import org.joda.time.Instant;
import
org.joda.time.LocalDate
;
import
org.joda.time.LocalDateTime
;
import
org.joda.time.LocalTime
;
import
org.joda.time.MutableDateTime
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -56,6 +55,7 @@ public class JodaTimeFormattingTests {
private
DataBinder
binder
;
@Before
public
void
setUp
()
{
JodaTimeFormatterRegistrar
registrar
=
new
JodaTimeFormatterRegistrar
();
...
...
@@ -85,6 +85,7 @@ public class JodaTimeFormattingTests {
JodaTimeContextHolder
.
setJodaTimeContext
(
null
);
}
@Test
public
void
testJodaTimePatternsForStyle
()
{
System
.
out
.
println
(
org
.
joda
.
time
.
format
.
DateTimeFormat
.
patternForStyle
(
"SS"
,
LocaleContextHolder
.
getLocale
()));
...
...
@@ -226,28 +227,33 @@ public class JodaTimeFormattingTests {
@Test
public
void
testBindLocalDateTime
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"localDateTime"
,
"10/31/09 12:00 PM"
);
propertyValues
.
add
(
"localDateTime"
,
new
LocalDateTime
(
2009
,
10
,
31
,
12
,
0
)
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"localDateTime"
));
String
value
=
binder
.
getBindingResult
().
getFieldValue
(
"localDateTime"
).
toString
();
assertTrue
(
value
.
startsWith
(
"10/31/09"
));
assertTrue
(
value
.
endsWith
(
"12:00 PM"
));
}
@Test
public
void
testBindLocalDateTimeAnnotated
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"localDateTimeAnnotated"
,
"Oct 31, 2009 12:00 PM"
);
propertyValues
.
add
(
"localDateTimeAnnotated"
,
new
LocalDateTime
(
2009
,
10
,
31
,
12
,
0
)
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"Oct 31, 2009 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"localDateTimeAnnotated"
));
String
value
=
binder
.
getBindingResult
().
getFieldValue
(
"localDateTimeAnnotated"
).
toString
();
assertTrue
(
value
.
startsWith
(
"Oct 31, 2009"
));
assertTrue
(
value
.
endsWith
(
"12:00 PM"
));
}
@Test
public
void
testBindDateTime
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"dateTime"
,
"10/31/09 12:00 PM"
);
propertyValues
.
add
(
"dateTime"
,
new
DateTime
(
2009
,
10
,
31
,
12
,
0
)
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"dateTime"
));
String
value
=
binder
.
getBindingResult
().
getFieldValue
(
"dateTime"
).
toString
();
assertTrue
(
value
.
startsWith
(
"10/31/09"
));
}
@Test
...
...
@@ -256,10 +262,12 @@ public class JodaTimeFormattingTests {
registrar
.
setDateTimeStyle
(
"MM"
);
setUp
(
registrar
);
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"localDateTime"
,
"Oct 31, 2009 12:00:00 PM"
);
propertyValues
.
add
(
"localDateTime"
,
new
LocalDateTime
(
2009
,
10
,
31
,
12
,
0
)
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"Oct 31, 2009 12:00:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"localDateTime"
));
String
value
=
binder
.
getBindingResult
().
getFieldValue
(
"localDateTime"
).
toString
();
assertTrue
(
value
.
startsWith
(
"Oct 31, 2009"
));
assertTrue
(
value
.
endsWith
(
"12:00:00 PM"
));
}
@Test
...
...
@@ -289,10 +297,11 @@ public class JodaTimeFormattingTests {
@Test
public
void
testBindDateTimeAnnotated
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"dateTimeAnnotated"
,
"Oct 31, 2009 12:00 PM"
);
propertyValues
.
add
(
"dateTimeAnnotated"
,
new
DateTime
(
2009
,
10
,
31
,
12
,
0
)
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"Oct 31, 2009 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"dateTimeAnnotated"
));
String
value
=
binder
.
getBindingResult
().
getFieldValue
(
"dateTimeAnnotated"
).
toString
();
assertTrue
(
value
.
startsWith
(
"Oct 31, 2009"
));
}
@Test
...
...
@@ -307,19 +316,11 @@ public class JodaTimeFormattingTests {
@Test
public
void
testBindDateTimeAnnotatedDefault
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"dateTimeAnnotatedDefault"
,
"10/31/09 12:00 PM"
);
propertyValues
.
add
(
"dateTimeAnnotatedDefault"
,
new
DateTime
(
2009
,
10
,
31
,
12
,
0
)
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"dateTimeAnnotatedDefault"
));
}
@Test
public
void
testBindDate
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"date"
,
"10/31/09 12:00 PM"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"date"
));
String
value
=
binder
.
getBindingResult
().
getFieldValue
(
"dateTimeAnnotatedDefault"
).
toString
();
assertTrue
(
value
.
startsWith
(
"10/31/09"
));
}
@Test
...
...
@@ -349,15 +350,6 @@ public class JodaTimeFormattingTests {
assertEquals
(
"10/31/09"
,
binder
.
getBindingResult
().
getFieldValue
(
"dateAnnotated"
));
}
@Test
public
void
testBindCalendar
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"calendar"
,
"10/31/09 12:00 PM"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"calendar"
));
}
@Test
public
void
testBindCalendarAnnotated
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
...
...
@@ -412,15 +404,6 @@ public class JodaTimeFormattingTests {
assertEquals
(
"2009-10-31T07:00:00.000-05:00"
,
binder
.
getBindingResult
().
getFieldValue
(
"isoDateTime"
));
}
@Test
public
void
testBindInstant
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"instant"
,
"10/31/09 12:00 PM"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"instant"
));
}
@Test
public
void
testBindInstantAnnotated
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
...
...
@@ -430,15 +413,6 @@ public class JodaTimeFormattingTests {
assertEquals
(
"2009-10-31T07:00:00.000-05:00"
,
binder
.
getBindingResult
().
getFieldValue
(
"instantAnnotated"
));
}
@Test
public
void
testBindMutableDateTime
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"mutableDateTime"
,
"10/31/09 12:00 PM"
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"mutableDateTime"
));
}
@Test
public
void
testBindMutableDateTimeAnnotated
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
...
...
@@ -512,9 +486,6 @@ public class JodaTimeFormattingTests {
@DateTimeFormat
(
style
=
"S-"
)
private
Date
dateAnnotated
;
@DateTimeFormat
private
Calendar
calendar
;
@DateTimeFormat
(
style
=
"S-"
)
private
Calendar
calendarAnnotated
;
...
...
@@ -537,13 +508,9 @@ public class JodaTimeFormattingTests {
@DateTimeFormat
(
iso
=
ISO
.
DATE_TIME
)
private
DateTime
isoDateTime
;
private
Instant
instant
;
@DateTimeFormat
(
iso
=
ISO
.
DATE_TIME
)
private
Instant
instantAnnotated
;
private
MutableDateTime
mutableDateTime
;
@DateTimeFormat
(
iso
=
ISO
.
DATE_TIME
)
private
Instant
mutableDateTimeAnnotated
;
...
...
@@ -645,14 +612,6 @@ public class JodaTimeFormattingTests {
this
.
dateAnnotated
=
dateAnnotated
;
}
public
Calendar
getCalendar
()
{
return
calendar
;
}
public
void
setCalendar
(
Calendar
calendar
)
{
this
.
calendar
=
calendar
;
}
public
Calendar
getCalendarAnnotated
()
{
return
calendarAnnotated
;
}
...
...
@@ -702,14 +661,6 @@ public class JodaTimeFormattingTests {
this
.
isoDateTime
=
isoDateTime
;
}
public
Instant
getInstant
()
{
return
instant
;
}
public
void
setInstant
(
Instant
instant
)
{
this
.
instant
=
instant
;
}
public
Instant
getInstantAnnotated
()
{
return
instantAnnotated
;
}
...
...
@@ -718,14 +669,6 @@ public class JodaTimeFormattingTests {
this
.
instantAnnotated
=
instantAnnotated
;
}
public
MutableDateTime
getMutableDateTime
()
{
return
mutableDateTime
;
}
public
void
setMutableDateTime
(
MutableDateTime
mutableDateTime
)
{
this
.
mutableDateTime
=
mutableDateTime
;
}
public
Instant
getMutableDateTimeAnnotated
()
{
return
mutableDateTimeAnnotated
;
}
...
...
spring-context/src/test/java/org/springframework/format/datetime/standard/DateTimeFormatterFactoryTests.java
浏览文件 @
f4f508d8
/*
* Copyright 2002-201
2
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.
...
...
@@ -78,7 +78,9 @@ public class DateTimeFormatterFactoryTests {
@Test
public
void
createDateTimeFormatterInOrderOfPropertyPriority
()
throws
Exception
{
factory
.
setStylePattern
(
"SS"
);
assertThat
(
applyLocale
(
factory
.
createDateTimeFormatter
()).
format
(
dateTime
),
is
(
"10/21/09 12:10 PM"
));
String
value
=
applyLocale
(
factory
.
createDateTimeFormatter
()).
format
(
dateTime
);
assertTrue
(
value
.
startsWith
(
"10/21/09"
));
assertTrue
(
value
.
endsWith
(
"12:10 PM"
));
factory
.
setIso
(
ISO
.
DATE
);
assertThat
(
applyLocale
(
factory
.
createDateTimeFormatter
()).
format
(
dateTime
),
is
(
"2009-10-21"
));
...
...
spring-context/src/test/java/org/springframework/format/datetime/standard/DateTimeFormattingTests.java
浏览文件 @
f4f508d8
/*
* Copyright 2002-201
3
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.
...
...
@@ -16,7 +16,6 @@
package
org.springframework.format.datetime.standard
;
import
java.text.DateFormat
;
import
java.time.Instant
;
import
java.time.LocalDate
;
import
java.time.LocalDateTime
;
...
...
@@ -25,10 +24,10 @@ import java.time.ZoneId;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.FormatStyle
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.GregorianCalendar
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
org.junit.After
;
import
org.junit.Before
;
...
...
@@ -55,6 +54,7 @@ public class DateTimeFormattingTests {
private
DataBinder
binder
;
@Before
public
void
setUp
()
{
DateTimeFormatterRegistrar
registrar
=
new
DateTimeFormatterRegistrar
();
...
...
@@ -84,6 +84,7 @@ public class DateTimeFormattingTests {
DateTimeContextHolder
.
setDateTimeContext
(
null
);
}
@Test
public
void
testBindLocalDate
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
...
...
@@ -235,19 +236,23 @@ public class DateTimeFormattingTests {
@Test
public
void
testBindLocalDateTime
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"localDateTime"
,
"10/31/09 12:00 PM"
);
propertyValues
.
add
(
"localDateTime"
,
LocalDateTime
.
of
(
2009
,
10
,
31
,
12
,
0
)
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"localDateTime"
));
String
value
=
binder
.
getBindingResult
().
getFieldValue
(
"localDateTime"
).
toString
();
assertTrue
(
value
.
startsWith
(
"10/31/09"
));
assertTrue
(
value
.
endsWith
(
"12:00 PM"
));
}
@Test
public
void
testBindLocalDateTimeAnnotated
()
{
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"localDateTimeAnnotated"
,
"Oct 31, 2009 12:00:00 PM"
);
propertyValues
.
add
(
"localDateTimeAnnotated"
,
LocalDateTime
.
of
(
2009
,
10
,
31
,
12
,
0
)
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"Oct 31, 2009 12:00:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"localDateTimeAnnotated"
));
String
value
=
binder
.
getBindingResult
().
getFieldValue
(
"localDateTimeAnnotated"
).
toString
();
assertTrue
(
value
.
startsWith
(
"Oct 31, 2009"
));
assertTrue
(
value
.
endsWith
(
"12:00:00 PM"
));
}
@Test
...
...
@@ -256,7 +261,9 @@ public class DateTimeFormattingTests {
propertyValues
.
add
(
"localDateTime"
,
new
GregorianCalendar
(
2009
,
9
,
31
,
12
,
0
));
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"10/31/09 12:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"localDateTime"
));
String
value
=
binder
.
getBindingResult
().
getFieldValue
(
"localDateTime"
).
toString
();
assertTrue
(
value
.
startsWith
(
"10/31/09"
));
assertTrue
(
value
.
endsWith
(
"12:00 PM"
));
}
@Test
...
...
@@ -265,10 +272,12 @@ public class DateTimeFormattingTests {
registrar
.
setDateTimeStyle
(
FormatStyle
.
MEDIUM
);
setUp
(
registrar
);
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"localDateTime"
,
"Oct 31, 2009 12:00:00 PM"
);
propertyValues
.
add
(
"localDateTime"
,
LocalDateTime
.
of
(
2009
,
10
,
31
,
12
,
0
)
);
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertEquals
(
"Oct 31, 2009 12:00:00 PM"
,
binder
.
getBindingResult
().
getFieldValue
(
"localDateTime"
));
String
value
=
binder
.
getBindingResult
().
getFieldValue
(
"localDateTime"
).
toString
();
assertTrue
(
value
.
startsWith
(
"Oct 31, 2009"
));
assertTrue
(
value
.
endsWith
(
"12:00:00 PM"
));
}
@Test
...
...
@@ -318,13 +327,11 @@ public class DateTimeFormattingTests {
@Test
public
void
testBindInstantFromJavaUtilDate
()
throws
Exception
{
DateFormat
df
=
DateFormat
.
getDateTimeInstance
(
DateFormat
.
SHORT
,
DateFormat
.
SHORT
,
Locale
.
US
);
df
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
MutablePropertyValues
propertyValues
=
new
MutablePropertyValues
();
propertyValues
.
add
(
"instant"
,
df
.
parse
(
"10/31/09 12:00 PM"
));
propertyValues
.
add
(
"instant"
,
new
Date
(
109
,
9
,
31
,
12
,
0
));
binder
.
bind
(
propertyValues
);
assertEquals
(
0
,
binder
.
getBindingResult
().
getErrorCount
());
assertTrue
(
binder
.
getBindingResult
().
getFieldValue
(
"instant"
).
toString
().
startsWith
(
"2009-10-31
T12:00
"
));
assertTrue
(
binder
.
getBindingResult
().
getFieldValue
(
"instant"
).
toString
().
startsWith
(
"2009-10-31"
));
}
...
...
spring-context/src/test/java/org/springframework/format/support/FormattingConversionServiceFactoryBeanTests.java
浏览文件 @
f4f508d8
/*
* Copyright 2002-201
2
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.
...
...
@@ -35,12 +35,12 @@ import org.springframework.format.FormatterRegistry;
import
org.springframework.format.Parser
;
import
org.springframework.format.Printer
;
import
org.springframework.format.annotation.NumberFormat
;
import
org.springframework.format.annotation.NumberFormat.Style
;
import
static
org
.
junit
.
Assert
.*;
/**
* @author Rossen Stoyanchev
* @author Juergen Hoeller
*/
public
class
FormattingConversionServiceFactoryBeanTests
{
...
...
@@ -49,11 +49,11 @@ public class FormattingConversionServiceFactoryBeanTests {
FormattingConversionServiceFactoryBean
factory
=
new
FormattingConversionServiceFactoryBean
();
factory
.
afterPropertiesSet
();
FormattingConversionService
fcs
=
factory
.
getObject
();
TypeDescriptor
descriptor
=
new
TypeDescriptor
(
TestBean
.
class
.
getDeclaredField
(
"p
ercent
"
));
Object
value
=
fcs
.
convert
(
"
5%
"
,
TypeDescriptor
.
valueOf
(
String
.
class
),
descriptor
);
assertEquals
(
.
05
,
value
);
value
=
fcs
.
convert
(
.
05
,
descriptor
,
TypeDescriptor
.
valueOf
(
String
.
class
));
assertEquals
(
"
5%
"
,
value
);
TypeDescriptor
descriptor
=
new
TypeDescriptor
(
TestBean
.
class
.
getDeclaredField
(
"p
attern
"
));
Object
value
=
fcs
.
convert
(
"
15,00
"
,
TypeDescriptor
.
valueOf
(
String
.
class
),
descriptor
);
assertEquals
(
15.0
,
value
);
value
=
fcs
.
convert
(
15.0
,
descriptor
,
TypeDescriptor
.
valueOf
(
String
.
class
));
assertEquals
(
"
15
"
,
value
);
}
@Test
...
...
@@ -62,9 +62,9 @@ public class FormattingConversionServiceFactoryBeanTests {
factory
.
setRegisterDefaultFormatters
(
false
);
factory
.
afterPropertiesSet
();
FormattingConversionService
fcs
=
factory
.
getObject
();
TypeDescriptor
descriptor
=
new
TypeDescriptor
(
TestBean
.
class
.
getDeclaredField
(
"p
ercent
"
));
TypeDescriptor
descriptor
=
new
TypeDescriptor
(
TestBean
.
class
.
getDeclaredField
(
"p
attern
"
));
try
{
fcs
.
convert
(
"
5%
"
,
TypeDescriptor
.
valueOf
(
String
.
class
),
descriptor
);
fcs
.
convert
(
"
15,00
"
,
TypeDescriptor
.
valueOf
(
String
.
class
),
descriptor
);
fail
(
"This format should not be parseable"
);
}
catch
(
ConversionFailedException
ex
)
{
...
...
@@ -128,10 +128,11 @@ public class FormattingConversionServiceFactoryBeanTests {
private
@interface
SpecialInt
{
}
private
static
class
TestBean
{
@NumberFormat
(
style
=
Style
.
PERCENT
)
private
double
p
ercent
;
@NumberFormat
(
pattern
=
"##,00"
)
private
double
p
attern
;
@SpecialInt
private
int
specialInt
;
...
...
@@ -143,9 +144,9 @@ public class FormattingConversionServiceFactoryBeanTests {
public
void
setSpecialInt
(
int
field
)
{
this
.
specialInt
=
field
;
}
}
private
static
class
TestBeanFormatter
implements
Formatter
<
TestBean
>
{
@Override
...
...
@@ -159,9 +160,9 @@ public class FormattingConversionServiceFactoryBeanTests {
object
.
setSpecialInt
(
Integer
.
parseInt
(
text
));
return
object
;
}
}
private
static
class
SpecialIntAnnotationFormatterFactory
implements
AnnotationFormatterFactory
<
SpecialInt
>
{
private
final
Set
<
Class
<?>>
fieldTypes
=
new
HashSet
<
Class
<?>>(
1
);
...
...
@@ -196,13 +197,13 @@ public class FormattingConversionServiceFactoryBeanTests {
}
}
private
static
class
TestFormatterRegistrar
implements
FormatterRegistrar
{
@Override
public
void
registerFormatters
(
FormatterRegistry
registry
)
{
registry
.
addFormatter
(
new
TestBeanFormatter
());
}
}
}
spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java
浏览文件 @
f4f508d8
...
...
@@ -40,18 +40,13 @@ import org.junit.Test;
/**
* Unit tests for {@link org.springframework.http.HttpHeaders}.
*
* @author Arjen Poutsma
* @author Sebastien Deleuze
*/
public
class
HttpHeadersTests
{
private
HttpHeaders
headers
;
@Before
public
void
setUp
()
{
headers
=
new
HttpHeaders
();
}
private
final
HttpHeaders
headers
=
new
HttpHeaders
();
@Test
...
...
@@ -67,7 +62,7 @@ public class HttpHeadersTests {
}
@Test
// SPR-9655
public
void
accept
i
Planet
()
{
public
void
accept
I
Planet
()
{
headers
.
add
(
"Accept"
,
"text/html"
);
headers
.
add
(
"Accept"
,
"text/plain"
);
List
<
MediaType
>
expected
=
Arrays
.
asList
(
new
MediaType
(
"text"
,
"html"
),
new
MediaType
(
"text"
,
"plain"
));
...
...
@@ -171,7 +166,7 @@ public class HttpHeadersTests {
assertEquals
(
"Invalid Date header"
,
"Thu, 18 Dec 2008 10:20:00 GMT"
,
headers
.
getFirst
(
"date"
));
// RFC 850
headers
.
set
(
"Date"
,
"Thu
rsday, 18-Dec-08 11:20:00 CE
T"
);
headers
.
set
(
"Date"
,
"Thu
, 18 Dec 2008 10:20:00 GM
T"
);
assertEquals
(
"Invalid Date header"
,
date
,
headers
.
getDate
());
}
...
...
spring-web/src/test/java/org/springframework/http/converter/json/GsonFactoryBeanTests.java
浏览文件 @
f4f508d8
...
...
@@ -131,7 +131,8 @@ public class GsonFactoryBeanTests {
Date
date
=
cal
.
getTime
();
bean
.
setDate
(
date
);
String
result
=
gson
.
toJson
(
bean
);
assertEquals
(
"{\"date\":\"Jan 1, 2014 12:00:00 AM\"}"
,
result
);
assertTrue
(
result
.
startsWith
(
"{\"date\":\"Jan 1, 2014"
));
assertTrue
(
result
.
endsWith
(
"12:00:00 AM\"}"
));
}
@Test
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录