Skip to content

Commit

Permalink
Add unit tests for me.zhengjie.utils.StringUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengjie committed May 8, 2019
1 parent 3cde757 commit 333212a
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.zhengjie.modules.security.service;

import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.*;
import me.zhengjie.exception.EntityNotFoundException;
import me.zhengjie.modules.system.repository.PermissionRepository;
Expand Down Expand Up @@ -40,7 +41,7 @@ public UserDetails loadUserByUsername(String username){

User user = userService.findByName(username);
if (user == null) {
throw new EntityNotFoundException(User.class, "name", username);
throw new BadRequestException("账号不存在");
} else {
return createJwtUser(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import me.zhengjie.domain.AlipayConfig;
import me.zhengjie.domain.vo.TradeVo;
import me.zhengjie.service.AlipayService;
import me.zhengjie.util.AliPayStatusEnum;
import me.zhengjie.util.AlipayUtils;
import me.zhengjie.utils.AliPayStatusEnum;
import me.zhengjie.utils.AlipayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.repository.AlipayRepository;
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.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import me.zhengjie.repository.QiNiuConfigRepository;
import me.zhengjie.repository.QiniuContentRepository;
import me.zhengjie.service.QiNiuService;
import me.zhengjie.util.QiNiuUtil;
import me.zhengjie.utils.QiNiuUtil;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -25,7 +25,6 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDate;
import java.util.Optional;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.zhengjie.util;
package me.zhengjie.utils;

/**
* 支付状态
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.zhengjie.util;
package me.zhengjie.utils;

import cn.hutool.core.util.StrUtil;
import com.alipay.api.AlipayApiException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.zhengjie.util;
package me.zhengjie.utils;

import com.qiniu.common.Zone;
import com.qiniu.storage.Configuration;
import me.zhengjie.utils.FileUtil;

import java.text.SimpleDateFormat;
import java.util.Date;

Expand Down

0 comments on commit 333212a

Please sign in to comment.