Add unit tests for me.zhengjie.utils.StringUtils

pull/62/head
zhengjie 2019-05-08 17:00:20 +08:00
parent 3cde757b32
commit 333212a15f
8 changed files with 59 additions and 10 deletions

View File

@ -0,0 +1,49 @@
package me.zhengjie.utils;
import org.junit.Test;
import org.springframework.mock.web.MockHttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
import static me.zhengjie.utils.StringUtils.*;
import static org.junit.Assert.*;
public class StringUtilsTest {
@Test
public void testInString() {
assertTrue(inString("?", "?"));
assertFalse(inString("?", new String[]{}));
}
@Test
public void testToCamelCase() {
assertNull(toCamelCase(null));
}
@Test
public void testToCapitalizeCamelCase() {
assertNull(StringUtils.toCapitalizeCamelCase(null));
assertEquals("HelloWorld", toCapitalizeCamelCase("hello_world"));
}
@Test
public void testToUnderScoreCase() {
assertNull(StringUtils.toUnderScoreCase(null));
assertEquals("hello_world", toUnderScoreCase("helloWorld"));
assertEquals("\u0000\u0000", toUnderScoreCase("\u0000\u0000"));
assertEquals("\u0000_a", toUnderScoreCase("\u0000A"));
}
@Test
public void testGetWeekDay() {
SimpleDateFormat simpleDateformat = new SimpleDateFormat("E");
assertEquals(simpleDateformat.format(new Date()), getWeekDay());
}
@Test
public void testGetIP() {
assertEquals("127.0.0.1", getIP(new MockHttpServletRequest()));
}
}

View File

@ -1,5 +1,6 @@
package me.zhengjie.modules.security.service; package me.zhengjie.modules.security.service;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.*; import me.zhengjie.modules.system.domain.*;
import me.zhengjie.exception.EntityNotFoundException; import me.zhengjie.exception.EntityNotFoundException;
import me.zhengjie.modules.system.repository.PermissionRepository; import me.zhengjie.modules.system.repository.PermissionRepository;
@ -40,7 +41,7 @@ public class JwtUserDetailsService implements UserDetailsService {
User user = userService.findByName(username); User user = userService.findByName(username);
if (user == null) { if (user == null) {
throw new EntityNotFoundException(User.class, "name", username); throw new BadRequestException("账号不存在");
} else { } else {
return createJwtUser(user); return createJwtUser(user);
} }

View File

@ -6,8 +6,8 @@ import me.zhengjie.aop.log.Log;
import me.zhengjie.domain.AlipayConfig; import me.zhengjie.domain.AlipayConfig;
import me.zhengjie.domain.vo.TradeVo; import me.zhengjie.domain.vo.TradeVo;
import me.zhengjie.service.AlipayService; import me.zhengjie.service.AlipayService;
import me.zhengjie.util.AliPayStatusEnum; import me.zhengjie.utils.AliPayStatusEnum;
import me.zhengjie.util.AlipayUtils; import me.zhengjie.utils.AlipayUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;

View File

@ -9,7 +9,7 @@ import me.zhengjie.domain.vo.TradeVo;
import me.zhengjie.exception.BadRequestException; import me.zhengjie.exception.BadRequestException;
import me.zhengjie.repository.AlipayRepository; import me.zhengjie.repository.AlipayRepository;
import me.zhengjie.service.AlipayService; import me.zhengjie.service.AlipayService;
import me.zhengjie.util.AlipayUtils; import me.zhengjie.utils.AlipayUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Propagation;

View File

@ -15,7 +15,7 @@ import me.zhengjie.exception.BadRequestException;
import me.zhengjie.repository.QiNiuConfigRepository; import me.zhengjie.repository.QiNiuConfigRepository;
import me.zhengjie.repository.QiniuContentRepository; import me.zhengjie.repository.QiniuContentRepository;
import me.zhengjie.service.QiNiuService; import me.zhengjie.service.QiNiuService;
import me.zhengjie.util.QiNiuUtil; import me.zhengjie.utils.QiNiuUtil;
import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -25,7 +25,6 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.time.LocalDate;
import java.util.Optional; import java.util.Optional;
/** /**

View File

@ -1,4 +1,4 @@
package me.zhengjie.util; package me.zhengjie.utils;
/** /**
* *

View File

@ -1,4 +1,4 @@
package me.zhengjie.util; package me.zhengjie.utils;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alipay.api.AlipayApiException; import com.alipay.api.AlipayApiException;

View File

@ -1,8 +1,8 @@
package me.zhengjie.util; package me.zhengjie.utils;
import com.qiniu.common.Zone; import com.qiniu.common.Zone;
import com.qiniu.storage.Configuration; import com.qiniu.storage.Configuration;
import me.zhengjie.utils.FileUtil;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;