Junit 单元测试类模板

提示:在项目整合完Junit之后,可以直接拷贝使用

package com.xxx.xxx.xxx;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xxx.xxx.xxxApplication;
import com.utils.RestTemplateUtil;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = xxxApplication.class)
public class TestInterface {

    @Autowired
    private RestTemplateUtil restTemplateUtil;

    /**
     * 日期操纵
     * */
    @Test
    public void test01() throws ParseException {
        //获取当前日期
        Date date = new Date();
        //将时间格式化成yyyy-MM-dd HH:mm:ss的格式
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        //创建Calendar实例
        Calendar cal = Calendar.getInstance();
        //设置当前时间
        cal.setTime(date);

        //在当前时间基础上减一年
//        cal.add(Calendar.YEAR, -1);
//        System.out.println(format.format(cal.getTime()));

        //在当前时间基础上减一月
//        cal.add(Calendar.MONTH,-1);
//        System.out.println("date============="+format.format(cal.getTime()));

        //同理增加一天的方法:
//        cal.add(Calendar.DATE, 1);
//        System.out.println(format.format(cal.getTime()));


    }

    @Test
    public void test02(){
        String s = "1322222224";
        String phone = s.length() > 11 ? s.substring(0,11) : s;
        System.out.println("phone"+phone);
        System.out.println("phone长度 = " + phone.length());
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值