forked from fanruan/finekit
Browse Source
* commit 'f70371559742c213d27d11cc4a39a13c73cec6ba': feat:针对pr进行补充和修改。补充单元测试,修改javadoc提示语 update: 针对pr进行修改。 feat: 改写mongodb插件时的第一次finekit补充。 feat: 新增toolbarDefremotes/1611766341912730171/master
superman
5 years ago
12 changed files with 151 additions and 3 deletions
@ -0,0 +1,14 @@
|
||||
package com.fanruan.api.err; |
||||
|
||||
/** |
||||
* 用来定义和JSON相关的异常 |
||||
* */ |
||||
public class JSONException extends com.fr.json.JSONException{ |
||||
public JSONException(String message) { |
||||
super(message); |
||||
} |
||||
|
||||
public JSONException(Throwable error) { |
||||
super(error); |
||||
} |
||||
} |
@ -0,0 +1,21 @@
|
||||
package com.fanruan.api.json; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
public class JSONKit { |
||||
/** |
||||
* 创建一个JSONObject对象 |
||||
* |
||||
* @return 一个JSONObject对象 |
||||
*/ |
||||
public static JSONObject create() { |
||||
return new JSONObject(); |
||||
} |
||||
/** |
||||
* 创建一个JSONObject对象 |
||||
* @param text 用来创建对象时的字符串 |
||||
* @return 一个JSONObject对象 |
||||
*/ |
||||
public static JSONObject create(String text) { |
||||
return new JSONObject(text); |
||||
} |
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import com.fr.stable.CodeUtils; |
||||
import com.fr.stable.CommonCodeUtils; |
||||
|
||||
public class CodeKit { |
||||
/** |
||||
* 给字符串解密 |
||||
* @param passwordText 待解密的字符串 |
||||
* @return 解密后的字符串 |
||||
*/ |
||||
public static String passwordDecode(String passwordText) { |
||||
return CodeUtils.passwordDecode(passwordText); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import com.fr.general.DateUtils; |
||||
|
||||
import java.util.Date; |
||||
|
||||
public class DateKit { |
||||
/** |
||||
* 将字符串转化为日期 |
||||
* |
||||
* @param str 字符串 |
||||
* @param returnNull 转化失败的时候是否返回null |
||||
* @return 将字符串转化为相应的日期值 |
||||
*/ |
||||
public static Date string2Date(String str, boolean returnNull) { |
||||
return DateUtils.string2Date(str, returnNull); |
||||
} |
||||
} |
@ -0,0 +1,15 @@
|
||||
package com.fanruan.api.json; |
||||
import com.fanruan.api.util.ArrayKit; |
||||
import com.fr.json.JSONObject; |
||||
|
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
public class JSONKitTest { |
||||
@Test |
||||
public void create() throws Exception{ |
||||
Assert.assertEquals(JSONKit.create(), new JSONObject()); |
||||
Assert.assertEquals(JSONKit.create("{test:123}"), new JSONObject("{test:123}")); |
||||
|
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import com.fr.stable.CommonCodeUtils; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
public class CodeKitTest { |
||||
@Test |
||||
public void passwordDecode(String passwordText) { |
||||
Assert.assertEquals(CodeKit.passwordDecode(passwordText), 123); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fanruan.api.util; |
||||
|
||||
import java.util.Date; |
||||
import java.text.DateFormat; |
||||
import java.text.SimpleDateFormat; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
public class DateKitTest { |
||||
@Test |
||||
public void string2Date() throws Exception{ |
||||
DateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd"); |
||||
Date myDate = dateFormat2.parse("2019-02-20"); |
||||
Assert.assertEquals(DateKit.string2Date("2019-02-20", false), myDate); |
||||
Assert.assertEquals(DateKit.string2Date("abcd", false), new Date()); |
||||
Assert.assertEquals(DateKit.string2Date("abcd", true), null); |
||||
} |
||||
} |
Loading…
Reference in new issue