package org.bvoid.engine.core;

import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.when;

import org.bvoid.engine.gfx.camera.CameraUpdateService;
import org.bvoid.engine.gfx.render.OpenglInitializer;
import org.bvoid.engine.gfx.view.View;
import org.bvoid.engine.input.InputService;
import org.bvoid.engine.window.GlfwInitializer;
import org.bvoid.engine.window.GlfwWindowCloser;
import org.bvoid.engine.window.GlfwWindowInitializer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class EngineTest {

  @InjectMocks
  private Engine classUnderTest;

  @Mock
  private GlfwInitializer glfwInitializer;
  @Mock
  private GlfwWindowInitializer glfwWindowInitializer;
  @Mock
  private OpenglInitializer openglInitializer;

  @Mock
  private GlfwWindowCloser windowCloser;

  @Mock
  private CameraUpdateService cameraUpdateSevice;
  @Mock
  private InputService inputService;
  @Mock
  private View view;

  private InOrder inOrder;

  @Before
  public void setUp() throws Exception {
    inOrder = inOrder(glfwInitializer, glfwWindowInitializer, openglInitializer, inputService,
        cameraUpdateSevice, view, windowCloser);
  }

  @Test
  public void testRunOnce() throws Exception {
    when(view.shouldClose()).thenReturn(false).thenReturn(true);

    classUnderTest.run();

    /**
     * INIT PHASE
     */
    inOrder.verify(glfwInitializer).init();
    inOrder.verify(glfwWindowInitializer).init();
    inOrder.verify(openglInitializer).init();

    /**
     * UPDATE PHASE
     */
    inOrder.verify(inputService).update();
    inOrder.verify(cameraUpdateSevice).update();
    inOrder.verify(view).update();

    /**
     * CLOSING PHASE
     */
    inOrder.verify(windowCloser).close();
  }

  @Test
  public void testRunTwice() throws Exception {
    when(view.shouldClose()).thenReturn(false).thenReturn(false).thenReturn(true);

    classUnderTest.run();

    /**
     * INIT PHASE
     */
    inOrder.verify(glfwInitializer).init();
    inOrder.verify(glfwWindowInitializer).init();
    inOrder.verify(openglInitializer).init();

    /**
     * UPDATE PHASE
     */
    inOrder.verify(inputService).update();
    inOrder.verify(cameraUpdateSevice).update();
    inOrder.verify(view).update();
    inOrder.verify(inputService).update();
    inOrder.verify(cameraUpdateSevice).update();
    inOrder.verify(view).update();

    /**
     * CLOSING PHASE
     */
    inOrder.verify(windowCloser).close();
  }

}

@@ -120,55 +120,79 @@
 ort 
-org.bvoid.engine.gfx.camera.CameraUpdateService
+java.util.List;%0A%0Aimport org.bvoid.engine.core.configuration.Initializer
 ;%0Aim
@@ -221,32 +221,34 @@
 gfx.
-render.OpenglInitializer
+camera.CameraUpdateService
 ;%0Aim
@@ -332,56 +332,8 @@
 ce;%0A
-import org.bvoid.engine.window.GlfwInitializer;%0A
 impo
@@ -381,62 +381,8 @@
 er;%0A
-import org.bvoid.engine.window.GlfwWindowInitializer;%0A
 impo
@@ -701,17 +701,16 @@
 erTest;%0A
-%0A
   @Mock%0A
@@ -723,160 +723,40 @@
 ate 
-GlfwInitializer glfwInitializer;%0A  @Mock%0A  private GlfwWindowInitializer glfwWindowInitializer;%0A  @Mock%0A  private OpenglInitializer openglInitializer
+List%3CInitializer%3E initializers
 ;%0A
-%0A
   @M
@@ -800,17 +800,16 @@
 Closer;%0A
-%0A
   @Mock%0A
@@ -1038,67 +1038,8 @@
 der(
-glfwInitializer, glfwWindowInitializer, openglInitializer, 
 inpu
@@ -1051,16 +1051,8 @@
 ice,
-%0A       
  cam
@@ -1246,183 +1246,8 @@
 );%0A%0A
-    /**%0A     * INIT PHASE%0A     */%0A    inOrder.verify(glfwInitializer).init();%0A    inOrder.verify(glfwWindowInitializer).init();%0A    inOrder.verify(openglInitializer).init();%0A%0A
     
@@ -1622,32 +1622,32 @@
 nReturn(true);%0A%0A
+
     classUnderTe
@@ -1661,183 +1661,8 @@
 );%0A%0A
-    /**%0A     * INIT PHASE%0A     */%0A    inOrder.verify(glfwInitializer).init();%0A    inOrder.verify(glfwWindowInitializer).init();%0A    inOrder.verify(openglInitializer).init();%0A%0A
     

test failed / still needs rethinking