Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
6cd2000f
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
6cd2000f
编写于
3月 18, 2020
作者:
kimmking
提交者:
GitHub
3月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add TypedPropertiesTest (#4817)
* add TypedPropertiesTest * modify code styles
上级
a6697dfc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
89 addition
and
3 deletion
+89
-3
shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/properties/TypedPropertyValue.java
...here/underlying/common/properties/TypedPropertyValue.java
+3
-3
shardingsphere-underlying/shardingsphere-common/src/test/java/org/apache/shardingsphere/underlying/common/properties/TypedPropertiesTest.java
...ere/underlying/common/properties/TypedPropertiesTest.java
+86
-0
未找到文件。
shardingsphere-underlying/shardingsphere-common/src/main/java/org/apache/shardingsphere/underlying/common/properties/TypedPropertyValue.java
浏览文件 @
6cd2000f
...
...
@@ -32,17 +32,17 @@ public final class TypedPropertyValue {
}
private
Object
createTypedValue
(
final
TypedPropertyKey
key
,
final
String
value
)
throws
TypedPropertyValueException
{
if
(
boolean
.
class
==
key
.
getType
())
{
if
(
boolean
.
class
==
key
.
getType
()
||
Boolean
.
class
==
key
.
getType
()
)
{
return
Boolean
.
valueOf
(
value
);
}
if
(
int
.
class
==
key
.
getType
())
{
if
(
int
.
class
==
key
.
getType
()
||
Integer
.
class
==
key
.
getType
()
)
{
try
{
return
Integer
.
valueOf
(
value
);
}
catch
(
final
NumberFormatException
ex
)
{
throw
new
TypedPropertyValueException
(
key
,
value
);
}
}
if
(
long
.
class
==
key
.
getType
())
{
if
(
long
.
class
==
key
.
getType
()
||
Long
.
class
==
key
.
getType
()
)
{
try
{
return
Long
.
valueOf
(
value
);
}
catch
(
final
NumberFormatException
ex
)
{
...
...
shardingsphere-underlying/shardingsphere-common/src/test/java/org/apache/shardingsphere/underlying/common/properties/TypedPropertiesTest.java
0 → 100644
浏览文件 @
6cd2000f
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.shardingsphere.underlying.common.properties
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
java.util.Properties
;
public
class
TypedPropertiesTest
{
@Test
public
void
assertTypes
()
throws
Exception
{
Properties
props
=
new
Properties
();
AProperties
properties
=
new
AProperties
(
APropertyKey
.
class
,
props
);
assertThat
(
properties
.
getValue
(
APropertyKey
.
A1
),
is
(
1
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A2
),
is
(
200L
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A3
),
is
(
Boolean
.
TRUE
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A4
),
is
(
"a4"
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A5
),
is
(
1
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A6
),
is
(
200L
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A7
),
is
(
Boolean
.
TRUE
));
// test override
props
.
put
(
"a1"
,
11
);
props
.
put
(
"a2"
,
222L
);
props
.
put
(
"a3"
,
Boolean
.
FALSE
);
props
.
put
(
"a4"
,
"a44"
);
props
.
put
(
"a5"
,
11
);
props
.
put
(
"a6"
,
222L
);
props
.
put
(
"a7"
,
Boolean
.
FALSE
);
properties
=
new
AProperties
(
APropertyKey
.
class
,
props
);
assertThat
(
properties
.
getValue
(
APropertyKey
.
A1
),
is
(
11
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A2
),
is
(
222L
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A3
),
is
(
Boolean
.
FALSE
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A4
),
is
(
"a44"
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A5
),
is
(
11
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A6
),
is
(
222L
));
assertThat
(
properties
.
getValue
(
APropertyKey
.
A7
),
is
(
Boolean
.
FALSE
));
}
@RequiredArgsConstructor
@Getter
private
enum
APropertyKey
implements
TypedPropertyKey
{
A1
(
"a1"
,
"1"
,
int
.
class
),
A2
(
"a2"
,
"200"
,
long
.
class
),
A3
(
"a3"
,
"true"
,
boolean
.
class
),
A4
(
"a4"
,
"a4"
,
String
.
class
),
A5
(
"a5"
,
"1"
,
Integer
.
class
),
A6
(
"a6"
,
"200"
,
Long
.
class
),
A7
(
"a7"
,
"true"
,
Boolean
.
class
);
private
final
String
key
;
private
final
String
defaultValue
;
private
final
Class
<?>
type
;
}
private
static
class
AProperties
extends
TypedProperties
<
APropertyKey
>
{
AProperties
(
final
Class
<
APropertyKey
>
keyClass
,
final
Properties
props
)
{
super
(
keyClass
,
props
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录