Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
23c2b6ad
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,发现更多精彩内容 >>
提交
23c2b6ad
编写于
7月 08, 2016
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added PathEditor for NIO file system resolution
Issue: SPR-14436
上级
40b2d26b
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
249 addition
and
57 deletion
+249
-57
spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java
.../springframework/beans/PropertyEditorRegistrySupport.java
+3
-0
spring-beans/src/main/java/org/springframework/beans/propertyeditors/FileEditor.java
...org/springframework/beans/propertyeditors/FileEditor.java
+4
-6
spring-beans/src/main/java/org/springframework/beans/propertyeditors/InputStreamEditor.java
...ingframework/beans/propertyeditors/InputStreamEditor.java
+3
-5
spring-beans/src/main/java/org/springframework/beans/propertyeditors/PathEditor.java
...org/springframework/beans/propertyeditors/PathEditor.java
+114
-0
spring-beans/src/main/java/org/springframework/beans/propertyeditors/ReaderEditor.java
...g/springframework/beans/propertyeditors/ReaderEditor.java
+3
-5
spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java
.../org/springframework/beans/propertyeditors/URIEditor.java
+3
-6
spring-beans/src/main/java/org/springframework/beans/propertyeditors/URLEditor.java
.../org/springframework/beans/propertyeditors/URLEditor.java
+2
-2
spring-beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java
...pringframework/beans/support/ResourceEditorRegistrar.java
+4
-1
spring-beans/src/test/java/org/springframework/beans/propertyeditors/FileEditorTests.java
...pringframework/beans/propertyeditors/FileEditorTests.java
+10
-9
spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java
...amework/beans/propertyeditors/InputStreamEditorTests.java
+2
-3
spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java
...pringframework/beans/propertyeditors/PathEditorTests.java
+80
-0
spring-beans/src/test/java/org/springframework/beans/propertyeditors/ReaderEditorTests.java
...ingframework/beans/propertyeditors/ReaderEditorTests.java
+2
-2
spring-beans/src/test/java/org/springframework/beans/propertyeditors/URIEditorTests.java
...springframework/beans/propertyeditors/URIEditorTests.java
+11
-10
spring-beans/src/test/java/org/springframework/beans/propertyeditors/URLEditorTests.java
...springframework/beans/propertyeditors/URLEditorTests.java
+8
-8
未找到文件。
spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java
浏览文件 @
23c2b6ad
...
...
@@ -25,6 +25,7 @@ import java.math.BigInteger;
import
java.net.URI
;
import
java.net.URL
;
import
java.nio.charset.Charset
;
import
java.nio.file.Path
;
import
java.util.Collection
;
import
java.util.Currency
;
import
java.util.HashMap
;
...
...
@@ -59,6 +60,7 @@ import org.springframework.beans.propertyeditors.FileEditor;
import
org.springframework.beans.propertyeditors.InputSourceEditor
;
import
org.springframework.beans.propertyeditors.InputStreamEditor
;
import
org.springframework.beans.propertyeditors.LocaleEditor
;
import
org.springframework.beans.propertyeditors.PathEditor
;
import
org.springframework.beans.propertyeditors.PatternEditor
;
import
org.springframework.beans.propertyeditors.PropertiesEditor
;
import
org.springframework.beans.propertyeditors.ReaderEditor
;
...
...
@@ -211,6 +213,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry {
this
.
defaultEditors
.
put
(
InputStream
.
class
,
new
InputStreamEditor
());
this
.
defaultEditors
.
put
(
InputSource
.
class
,
new
InputSourceEditor
());
this
.
defaultEditors
.
put
(
Locale
.
class
,
new
LocaleEditor
());
this
.
defaultEditors
.
put
(
Path
.
class
,
new
PathEditor
());
this
.
defaultEditors
.
put
(
Pattern
.
class
,
new
PatternEditor
());
this
.
defaultEditors
.
put
(
Properties
.
class
,
new
PropertiesEditor
());
this
.
defaultEditors
.
put
(
Reader
.
class
,
new
ReaderEditor
());
...
...
spring-beans/src/main/java/org/springframework/beans/propertyeditors/FileEditor.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -59,16 +59,14 @@ public class FileEditor extends PropertyEditorSupport {
/**
* Create a new FileEditor,
* using the default ResourceEditor underneath.
* Create a new FileEditor, using a default ResourceEditor underneath.
*/
public
FileEditor
()
{
this
.
resourceEditor
=
new
ResourceEditor
();
}
/**
* Create a new FileEditor,
* using the given ResourceEditor underneath.
* Create a new FileEditor, using the given ResourceEditor underneath.
* @param resourceEditor the ResourceEditor to use
*/
public
FileEditor
(
ResourceEditor
resourceEditor
)
{
...
...
@@ -105,7 +103,7 @@ public class FileEditor extends PropertyEditorSupport {
}
catch
(
IOException
ex
)
{
throw
new
IllegalArgumentException
(
"Could not retrieve
F
ile for "
+
resource
+
": "
+
ex
.
getMessage
());
"Could not retrieve
f
ile for "
+
resource
+
": "
+
ex
.
getMessage
());
}
}
else
{
...
...
spring-beans/src/main/java/org/springframework/beans/propertyeditors/InputStreamEditor.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -47,16 +47,14 @@ public class InputStreamEditor extends PropertyEditorSupport {
/**
* Create a new InputStreamEditor,
* using the default ResourceEditor underneath.
* Create a new InputStreamEditor, using the default ResourceEditor underneath.
*/
public
InputStreamEditor
()
{
this
.
resourceEditor
=
new
ResourceEditor
();
}
/**
* Create a new InputStreamEditor,
* using the given ResourceEditor underneath.
* Create a new InputStreamEditor, using the given ResourceEditor underneath.
* @param resourceEditor the ResourceEditor to use
*/
public
InputStreamEditor
(
ResourceEditor
resourceEditor
)
{
...
...
spring-beans/src/main/java/org/springframework/beans/propertyeditors/PathEditor.java
0 → 100644
浏览文件 @
23c2b6ad
/*
* Copyright 2002-2016 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.beans.propertyeditors
;
import
java.beans.PropertyEditorSupport
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.nio.file.FileSystemNotFoundException
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
org.springframework.core.io.Resource
;
import
org.springframework.core.io.ResourceEditor
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.util.Assert
;
/**
* Editor for {@code java.nio.file.Path}, to directly populate a Path
* property instead of using a String property as bridge.
*
* <p>Based on {@link Paths#get(URI)}'s resolution algorithm, checking
* registered NIO file system providers, including the default file system
* for "file:..." paths. Also supports Spring-style URL notation: any fully
* qualified standard URL and Spring's special "classpath:" pseudo-URL,
* as well as Spring's context-specific relative file paths.
*
* <p>Note that, in contrast to {@link FileEditor}, relative paths are only
* supported by Spring's resource abstraction here. Direct {@code Paths.get}
* resolution in a file system always has to go through the corresponding
* file system provider's scheme, i.e. "file" for the default file system.
*
* @author Juergen Hoeller
* @since 4.3.2
* @see java.nio.file.Path
* @see Paths#get(URI)
* @see ResourceEditor
* @see org.springframework.core.io.ResourceLoader
* @see FileEditor
* @see URLEditor
*/
public
class
PathEditor
extends
PropertyEditorSupport
{
private
final
ResourceEditor
resourceEditor
;
/**
* Create a new PathEditor, using the default ResourceEditor underneath.
*/
public
PathEditor
()
{
this
.
resourceEditor
=
new
ResourceEditor
();
}
/**
* Create a new PathEditor, using the given ResourceEditor underneath.
* @param resourceEditor the ResourceEditor to use
*/
public
PathEditor
(
ResourceEditor
resourceEditor
)
{
Assert
.
notNull
(
resourceEditor
,
"ResourceEditor must not be null"
);
this
.
resourceEditor
=
resourceEditor
;
}
@Override
public
void
setAsText
(
String
text
)
throws
IllegalArgumentException
{
if
(!
text
.
startsWith
(
"/"
)
&&
!
text
.
startsWith
(
ResourceLoader
.
CLASSPATH_URL_PREFIX
))
{
try
{
URI
uri
=
new
URI
(
text
);
if
(
uri
.
getScheme
()
!=
null
)
{
// Let's try NIO file system providers via Paths.get(URI)
setValue
(
Paths
.
get
(
uri
).
normalize
());
return
;
}
}
catch
(
URISyntaxException
ex
)
{
// Not a valid URI: Let's try as Spring resource location.
}
catch
(
FileSystemNotFoundException
ex
)
{
// URI scheme not registered for NIO:
// Let's try URL protocol handlers via Spring's resource mechanism.
}
}
this
.
resourceEditor
.
setAsText
(
text
);
Resource
resource
=
(
Resource
)
this
.
resourceEditor
.
getValue
();
try
{
setValue
(
resource
!=
null
?
resource
.
getFile
().
toPath
()
:
null
);
}
catch
(
IOException
ex
)
{
throw
new
IllegalArgumentException
(
"Failed to retrieve file for "
+
resource
,
ex
);
}
}
@Override
public
String
getAsText
()
{
Path
value
=
(
Path
)
getValue
();
return
(
value
!=
null
?
value
.
toString
()
:
""
);
}
}
spring-beans/src/main/java/org/springframework/beans/propertyeditors/ReaderEditor.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -47,16 +47,14 @@ public class ReaderEditor extends PropertyEditorSupport {
/**
* Create a new ReaderEditor,
* using the default ResourceEditor underneath.
* Create a new ReaderEditor, using the default ResourceEditor underneath.
*/
public
ReaderEditor
()
{
this
.
resourceEditor
=
new
ResourceEditor
();
}
/**
* Create a new ReaderEditor,
* using the given ResourceEditor underneath.
* Create a new ReaderEditor, using the given ResourceEditor underneath.
* @param resourceEditor the ResourceEditor to use
*/
public
ReaderEditor
(
ResourceEditor
resourceEditor
)
{
...
...
spring-beans/src/main/java/org/springframework/beans/propertyeditors/URIEditor.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -60,8 +60,7 @@ public class URIEditor extends PropertyEditorSupport {
* standard URIs (not trying to resolve them into physical resources).
*/
public
URIEditor
()
{
this
.
classLoader
=
null
;
this
.
encode
=
true
;
this
(
true
);
}
/**
...
...
@@ -74,7 +73,6 @@ public class URIEditor extends PropertyEditorSupport {
this
.
encode
=
encode
;
}
/**
* Create a new URIEditor, using the given ClassLoader to resolve
* "classpath:" locations into physical resource URLs.
...
...
@@ -82,8 +80,7 @@ public class URIEditor extends PropertyEditorSupport {
* (may be {@code null} to indicate the default ClassLoader)
*/
public
URIEditor
(
ClassLoader
classLoader
)
{
this
.
classLoader
=
(
classLoader
!=
null
?
classLoader
:
ClassUtils
.
getDefaultClassLoader
());
this
.
encode
=
true
;
this
(
classLoader
,
true
);
}
/**
...
...
spring-beans/src/main/java/org/springframework/beans/propertyeditors/URLEditor.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-201
2
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -50,7 +50,7 @@ public class URLEditor extends PropertyEditorSupport {
/**
* Create a new URLEditor, using
the
default ResourceEditor underneath.
* Create a new URLEditor, using
a
default ResourceEditor underneath.
*/
public
URLEditor
()
{
this
.
resourceEditor
=
new
ResourceEditor
();
...
...
spring-beans/src/main/java/org/springframework/beans/support/ResourceEditorRegistrar.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -22,6 +22,7 @@ import java.io.InputStream;
import
java.io.Reader
;
import
java.net.URI
;
import
java.net.URL
;
import
java.nio.file.Path
;
import
org.xml.sax.InputSource
;
...
...
@@ -33,6 +34,7 @@ import org.springframework.beans.propertyeditors.ClassEditor;
import
org.springframework.beans.propertyeditors.FileEditor
;
import
org.springframework.beans.propertyeditors.InputSourceEditor
;
import
org.springframework.beans.propertyeditors.InputStreamEditor
;
import
org.springframework.beans.propertyeditors.PathEditor
;
import
org.springframework.beans.propertyeditors.ReaderEditor
;
import
org.springframework.beans.propertyeditors.URIEditor
;
import
org.springframework.beans.propertyeditors.URLEditor
;
...
...
@@ -103,6 +105,7 @@ public class ResourceEditorRegistrar implements PropertyEditorRegistrar {
doRegisterEditor
(
registry
,
InputStream
.
class
,
new
InputStreamEditor
(
baseEditor
));
doRegisterEditor
(
registry
,
InputSource
.
class
,
new
InputSourceEditor
(
baseEditor
));
doRegisterEditor
(
registry
,
File
.
class
,
new
FileEditor
(
baseEditor
));
doRegisterEditor
(
registry
,
Path
.
class
,
new
PathEditor
(
baseEditor
));
doRegisterEditor
(
registry
,
Reader
.
class
,
new
ReaderEditor
(
baseEditor
));
doRegisterEditor
(
registry
,
URL
.
class
,
new
URLEditor
(
baseEditor
));
...
...
spring-beans/src/test/java/org/springframework/beans/propertyeditors/FileEditorTests.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-20
08
the original author or authors.
* Copyright 2002-20
16
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.
...
...
@@ -29,20 +29,20 @@ import static org.junit.Assert.*;
* @author Thomas Risberg
* @author Chris Beams
*/
public
final
class
FileEditorTests
{
public
class
FileEditorTests
{
@Test
public
void
testClasspathFileName
()
throws
Exception
{
PropertyEditor
fileEditor
=
new
FileEditor
();
fileEditor
.
setAsText
(
"classpath:"
+
ClassUtils
.
classPackageAsResourcePath
(
getClass
())
+
"/"
+
ClassUtils
.
getShortName
(
getClass
())
+
".class"
);
fileEditor
.
setAsText
(
"classpath:"
+
ClassUtils
.
classPackageAsResourcePath
(
getClass
())
+
"/"
+
ClassUtils
.
getShortName
(
getClass
())
+
".class"
);
Object
value
=
fileEditor
.
getValue
();
assertTrue
(
value
instanceof
File
);
File
file
=
(
File
)
value
;
assertTrue
(
file
.
exists
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testWithNonExistentResource
()
throws
Exception
{
PropertyEditor
propertyEditor
=
new
FileEditor
();
propertyEditor
.
setAsText
(
"classpath:no_way_this_file_is_found.doc"
);
...
...
@@ -71,8 +71,8 @@ public final class FileEditorTests {
@Test
public
void
testUnqualifiedFileNameFound
()
throws
Exception
{
PropertyEditor
fileEditor
=
new
FileEditor
();
String
fileName
=
ClassUtils
.
classPackageAsResourcePath
(
getClass
())
+
"/"
+
ClassUtils
.
getShortName
(
getClass
())
+
".class"
;
String
fileName
=
ClassUtils
.
classPackageAsResourcePath
(
getClass
())
+
"/"
+
ClassUtils
.
getShortName
(
getClass
())
+
".class"
;
fileEditor
.
setAsText
(
fileName
);
Object
value
=
fileEditor
.
getValue
();
assertTrue
(
value
instanceof
File
);
...
...
@@ -88,8 +88,8 @@ public final class FileEditorTests {
@Test
public
void
testUnqualifiedFileNameNotFound
()
throws
Exception
{
PropertyEditor
fileEditor
=
new
FileEditor
();
String
fileName
=
ClassUtils
.
classPackageAsResourcePath
(
getClass
())
+
"/"
+
ClassUtils
.
getShortName
(
getClass
())
+
".clazz"
;
String
fileName
=
ClassUtils
.
classPackageAsResourcePath
(
getClass
())
+
"/"
+
ClassUtils
.
getShortName
(
getClass
())
+
".clazz"
;
fileEditor
.
setAsText
(
fileName
);
Object
value
=
fileEditor
.
getValue
();
assertTrue
(
value
instanceof
File
);
...
...
@@ -101,4 +101,5 @@ public final class FileEditorTests {
}
assertTrue
(
absolutePath
.
endsWith
(
fileName
));
}
}
spring-beans/src/test/java/org/springframework/beans/propertyeditors/InputStreamEditorTests.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -60,9 +60,8 @@ public class InputStreamEditorTests {
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testWhenResourceDoesNotExist
()
throws
Exception
{
String
resource
=
"classpath:bingo!"
;
InputStreamEditor
editor
=
new
InputStreamEditor
();
editor
.
setAsText
(
resource
);
editor
.
setAsText
(
"classpath:bingo!"
);
}
@Test
...
...
spring-beans/src/test/java/org/springframework/beans/propertyeditors/PathEditorTests.java
0 → 100644
浏览文件 @
23c2b6ad
/*
* Copyright 2002-2016 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.beans.propertyeditors
;
import
java.beans.PropertyEditor
;
import
java.io.File
;
import
java.nio.file.Path
;
import
org.junit.Test
;
import
org.springframework.util.ClassUtils
;
import
static
org
.
junit
.
Assert
.*;
/**
* @author Juergen Hoeller
* @since 4.3.2
*/
public
class
PathEditorTests
{
@Test
public
void
testClasspathPathName
()
throws
Exception
{
PropertyEditor
pathEditor
=
new
PathEditor
();
pathEditor
.
setAsText
(
"classpath:"
+
ClassUtils
.
classPackageAsResourcePath
(
getClass
())
+
"/"
+
ClassUtils
.
getShortName
(
getClass
())
+
".class"
);
Object
value
=
pathEditor
.
getValue
();
assertTrue
(
value
instanceof
Path
);
Path
path
=
(
Path
)
value
;
assertTrue
(
path
.
toFile
().
exists
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testWithNonExistentResource
()
throws
Exception
{
PropertyEditor
propertyEditor
=
new
PathEditor
();
propertyEditor
.
setAsText
(
"classpath:/no_way_this_file_is_found.doc"
);
}
@Test
public
void
testWithNonExistentPath
()
throws
Exception
{
PropertyEditor
pathEditor
=
new
PathEditor
();
pathEditor
.
setAsText
(
"file:/no_way_this_file_is_found.doc"
);
Object
value
=
pathEditor
.
getValue
();
assertTrue
(
value
instanceof
Path
);
Path
path
=
(
Path
)
value
;
assertTrue
(!
path
.
toFile
().
exists
());
}
@Test
public
void
testUnqualifiedPathNameFound
()
throws
Exception
{
PropertyEditor
pathEditor
=
new
PathEditor
();
String
fileName
=
ClassUtils
.
classPackageAsResourcePath
(
getClass
())
+
"/"
+
ClassUtils
.
getShortName
(
getClass
())
+
".class"
;
pathEditor
.
setAsText
(
fileName
);
Object
value
=
pathEditor
.
getValue
();
assertTrue
(
value
instanceof
Path
);
Path
path
=
(
Path
)
value
;
File
file
=
path
.
toFile
();
assertTrue
(
file
.
exists
());
String
absolutePath
=
file
.
getAbsolutePath
();
if
(
File
.
separatorChar
==
'\\'
)
{
absolutePath
=
absolutePath
.
replace
(
'\\'
,
'/'
);
}
assertTrue
(
absolutePath
.
endsWith
(
fileName
));
}
}
spring-beans/src/test/java/org/springframework/beans/propertyeditors/ReaderEditorTests.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -34,7 +34,7 @@ public class ReaderEditorTests {
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testCtorWithNullResourceEditor
()
throws
Exception
{
new
InputStream
Editor
(
null
);
new
Reader
Editor
(
null
);
}
@Test
...
...
spring-beans/src/test/java/org/springframework/beans/propertyeditors/URIEditorTests.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-201
0
the original author or authors.
* Copyright 2002-201
6
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.
...
...
@@ -31,15 +31,6 @@ import static org.junit.Assert.*;
*/
public
class
URIEditorTests
{
private
void
doTestURI
(
String
uriSpec
)
{
PropertyEditor
uriEditor
=
new
URIEditor
();
uriEditor
.
setAsText
(
uriSpec
);
Object
value
=
uriEditor
.
getValue
();
assertTrue
(
value
instanceof
URI
);
URI
uri
=
(
URI
)
value
;
assertEquals
(
uriSpec
,
uri
.
toString
());
}
@Test
public
void
standardURI
()
throws
Exception
{
doTestURI
(
"mailto:juergen.hoeller@interface21.com"
);
...
...
@@ -141,4 +132,14 @@ public class URIEditorTests {
assertEquals
(
"http://example.com/spaces%20and%20%E2%82%AC"
,
uri
.
toASCIIString
());
}
private
void
doTestURI
(
String
uriSpec
)
{
PropertyEditor
uriEditor
=
new
URIEditor
();
uriEditor
.
setAsText
(
uriSpec
);
Object
value
=
uriEditor
.
getValue
();
assertTrue
(
value
instanceof
URI
);
URI
uri
=
(
URI
)
value
;
assertEquals
(
uriSpec
,
uri
.
toString
());
}
}
spring-beans/src/test/java/org/springframework/beans/propertyeditors/URLEditorTests.java
浏览文件 @
23c2b6ad
/*
* Copyright 2002-20
0
6 the original author or authors.
* Copyright 2002-20
1
6 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.
...
...
@@ -29,7 +29,12 @@ import static org.junit.Assert.*;
* @author Rick Evans
* @author Chris Beams
*/
public
final
class
URLEditorTests
{
public
class
URLEditorTests
{
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testCtorWithNullResourceEditor
()
throws
Exception
{
new
URLEditor
(
null
);
}
@Test
public
void
testStandardURI
()
throws
Exception
{
...
...
@@ -63,7 +68,7 @@ public final class URLEditorTests {
assertTrue
(!
url
.
getProtocol
().
startsWith
(
"classpath"
));
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testWithNonExistentResource
()
throws
Exception
{
PropertyEditor
urlEditor
=
new
URLEditor
();
urlEditor
.
setAsText
(
"gonna:/freak/in/the/morning/freak/in/the.evening"
);
...
...
@@ -83,9 +88,4 @@ public final class URLEditorTests {
assertEquals
(
""
,
urlEditor
.
getAsText
());
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testCtorWithNullResourceEditor
()
throws
Exception
{
new
URLEditor
(
null
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录