package com.sptg.permissions.biz.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.sptg.permissions.api.entity.Menu;
import lombok.extern.slf4j.Slf4j;
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.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * title: AccountServiceImplTest
 * package: com.sptg.permissions.biz.security
 * description: 账号-服务层接口实现类测试用例
 *
 *                  
 *                 
 */
@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class AccountServiceImplTest {

    @Autowired
    private MenuServiceInterface menuServiceInterface;

    @Test
    public void testSelectByLoginName(){
        Wrapper<Menu> wrapper = new EntityWrapper<>();
        List<Menu> menuList = this.menuServiceInterface.selectList(wrapper);

        log.warn("-----------------------------------");
        log.warn("总数：" + String.valueOf(menuList.size()));

        long bTime1 = System.nanoTime();
        List<Long> idList = new ArrayList<>(menuList.size());
        menuList.forEach(menu -> idList.add(menu.getId()));
        long eTime1 = System.nanoTime();

        long bTime2 = System.nanoTime();
        List<Long> list = menuList.stream().map(Menu::getId).collect(Collectors.toList());
        long eTime2 = System.nanoTime();

        long count1 = eTime1 - bTime1;
        long count2 = eTime2 - bTime2;

        log.warn("for：" + count1);
        log.warn("stream：" + count2);

    }

}
