@@ -0,0 +1,2094 @@
+import com.zte.iot.domain.StudentEntity;%0Aimport org.junit.jupiter.api.Assertions;%0Aimport org.junit.jupiter.api.Test;%0A%0Aimport java.util.Optional;%0A%0A/**%0A * %E6%B5%8B%E8%AF%95Optional%E7%9A%84map%E3%80%81filter%E3%80%81flatmap%E6%96%B9%E6%B3%95%0A */%0Apublic class OptionalTest %7B%0A%0A    @Test%0A    public void test01_a() %7B%0A        StudentEntity studentEntity = new StudentEntity(1, %2211%22, 111);%0A%0A        final Optional%3CStudentEntity%3E optional = Optional.ofNullable(studentEntity);%0A        //map%E6%96%B9%E6%B3%95%0A        Integer actual = optional.map(StudentEntity::getAge).orElse(-1);%0A        Assertions.assertEquals(111, actual);%0A%0A        //filter%E6%96%B9%E6%B3%95%0A        Assertions.assertTrue(optional.filter(s -%3E s.getAge() %3E 1).isPresent());%0A        Assertions.assertFalse(optional.filter(s -%3E s.getAge() %3E 1000).isPresent());%0A    %7D%0A%0A    @Test%0A    public void test01_b() %7B%0A        StudentEntity studentEntity = null;%0A%0A        final Optional%3CStudentEntity%3E optional = Optional.ofNullable(studentEntity);%0A        //map%E6%96%B9%E6%B3%95%0A        Integer actual = optional.map(StudentEntity::getAge).orElse(-1);%0A        Assertions.assertEquals(-1, actual);%0A%0A        //filter%E6%96%B9%E6%B3%95%0A        Assertions.assertFalse(optional.filter(s -%3E s.getAge() %3E 1).isPresent());%0A        Assertions.assertFalse(optional.filter(s -%3E s.getAge() %3E 1000).isPresent());%0A    %7D%0A%0A    @Test%0A    public void test_flatmap_01() %7B%0A        //%E6%B5%8B%E8%AF%95flatmap:%0A        //Use map if the function returns the object%0A        //Use flatMap if the function returns an Optional.%0A        StudentEntity studentEntity = new StudentEntity(1, %2211%22, 21);%0A        final Optional%3CStudentEntity%3E optional = Optional.ofNullable(studentEntity);%0A%0A        boolean actual = optional.flatMap(s -%3E %7B%0A            //flatmap%E6%98%AF%E8%BF%94%E5%9B%9EOptional%0A            if (s.getAge() %3E 18) %7B%0A                return Optional.of(s);%0A            %7D%0A            return Optional.empty();%0A        %7D).isPresent();%0A        Assertions.assertTrue(actual);%0A%0A        boolean actual222 = optional.map(s -%3E %7B%0A            //map%E7%9B%B4%E6%8E%A5%E8%BF%94%E5%9B%9E%E5%AF%B9%E8%B1%A1%0A            if (s.getAge() %3E 18) %7B%0A                return s;%0A            %7D%0A            return null;%0A%0A        %7D).isPresent();%0A        Assertions.assertTrue(actual222);%0A%0A%0A    %7D%0A%7D%0A

Create OptionalTest.java