package com.github.j9Stream;

import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static junit.framework.Assert.assertEquals;

public class StreamTest {

    @Test
    public void dropWhile() throws Exception {
        // arrange
        List<Integer> list = Arrays.asList(0, 1, 2, 3, 4);

        // act
        List<Integer> actual = list.stream().dropWhile(x -> x < 3).collect(Collectors.toList());

        // assert
        assertEquals(2, actual.size());
        assertEquals(3, actual.get(0).intValue());
        assertEquals(4, actual.get(1).intValue());
    }

    @Test
    public void takeWhile() throws Exception {
        // arrange
        List<Integer> list = Arrays.asList(0, 1, 2, 3, 4);

        // act
        List<Integer> actual = list.stream().takeWhile(x -> x < 3).collect(Collectors.toList());

        // assert
        assertEquals(3, actual.size());
        assertEquals(0, actual.get(0).intValue());
        assertEquals(1, actual.get(1).intValue());
        assertEquals(2, actual.get(2).intValue());
    }

    @Test
    public void ofNullable() throws Exception {
        // arrange
        List<String> list = Arrays.asList("Angular", "React");
        Map<String, Integer> map = new HashMap<>() {
            {
                put("Backbone", 1);
                put("Angular", 2);
                put("React", 3);
            }
        };

        // act
        List<Integer> actual = list.stream().flatMap(str -> Stream.ofNullable(map.get(str))).collect(Collectors.toList());

        // assert
        assertEquals(2, actual.get(0).intValue());
        assertEquals(3, actual.get(1).intValue());
    }
}

@@ -1303,16 +1303,23 @@
 ngular%22,
+ %22ES7%22,
  %22React%22
@@ -1413,16 +1413,15 @@
 ut(%22
-Backbone
+Angular
 %22, 1
@@ -1444,23 +1444,22 @@
    put(%22
-Angular
+ES2016
 %22, 2);%0A 
@@ -1688,32 +1688,72 @@
  assertEquals(2,
+ actual.size());%0A        assertEquals(1,
  actual.get(0).i

fix ofNullable (JDK-8050819)