1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| package io.github.vampireachao.stream.plugin.mybatisplus;
import com.baomidou.mybatisplus.test.autoconfigure.MybatisPlusTest; import io.github.vampireachao.stream.plugin.mybatisplus.pojo.po.UserInfo; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test;
import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map;
@MybatisPlusTest class OneToManyTest { @Test void testQuery() { Assertions.assertAll(() -> { List<Integer> userAges = Arrays.asList(18, 18, 28, 21, 24); Map<Integer, List<UserInfo>> ageUsersMap = OneToMany.query(userAges, UserInfo::getAge); Assertions.assertEquals(4, ageUsersMap.size());
Map<Integer, List<String>> userAgeNameMap = OneToMany.query(userAges, UserInfo::getAge, UserInfo::getName); Assertions.assertEquals(4, userAgeNameMap.size());
userAgeNameMap = OneToMany.query(w -> w.le(UserInfo::getAge, 22), userAges, UserInfo::getAge, UserInfo::getName); Assertions.assertEquals(2, userAgeNameMap.size());
ageUsersMap = OneToMany.query(18, UserInfo::getAge); Assertions.assertEquals(1, ageUsersMap.size());
userAgeNameMap = OneToMany.query(18, UserInfo::getAge, UserInfo::getName); Assertions.assertEquals(1, userAgeNameMap.size());
userAgeNameMap = OneToMany.query(w -> w.le(UserInfo::getAge, 22), 18, UserInfo::getAge, UserInfo::getName); Assertions.assertEquals(1, userAgeNameMap.size());
Map<Integer, List<Boolean>> query = OneToMany.query(w -> w.select(UserInfo::getAge, UserInfo::getName), userAges, UserInfo::getAge, userInfo -> userInfo.getName() != null && userInfo.getName().contains("a")); Assertions.assertEquals(2, query.values().stream().flatMap(Collection::stream).filter(Boolean::booleanValue).count()); }); } }
|