package ru.job4j.multithreading.waitnotifyall;

import org.junit.Test;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

public class SimpleBlockingQueueTest {
    /**
     * Simple test.
     */
    @Test
    public void whenOfferValueThenCanPollIt() {
        SimpleBlockingQueue<Integer> queue = new SimpleBlockingQueue<>(3);

        queue.offer(1);
        queue.offer(2);
        queue.offer(3);

        queue.poll();
        queue.poll();
        int result = queue.poll();

        assertThat(result, is(3));
    }

    /**
     * Simple test not working.
     */
    @Test
    public void whenOfferValueThenCannotPollIt() {
        SimpleBlockingQueue<Integer> queue = new SimpleBlockingQueue<>(3);

        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                queue.poll();
            }
        }

        ).start();
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        queue.offer(4);

        queue.poll();
        queue.poll();
        int result = queue.poll();

        assertThat(result, is(4));
    }

}
@@ -650,32 +650,60 @@
 enCannotPollIt()
+ throws InterruptedException
  %7B%0A        Simpl
@@ -772,16 +772,31 @@
 %0A       
+ Thread first =
  new Thr
@@ -1091,25 +1091,26 @@
  %7D%0A        %7D
-%0A
+);
 %0A        ).s
@@ -1106,17 +1106,21 @@
         
-)
+first
 .start()
@@ -1117,24 +1117,48 @@
 st.start();%0A
+%0A        first.join();%0A%0A
         queu

review - 1. Реализовать шаблон Producer Consumer. task - 1098