package eu.ydp.empiria.player.client.module.expression.evaluate;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.stub;
import static org.mockito.Mockito.verify;

import org.junit.Before;
import org.junit.Test;

import eu.ydp.empiria.player.client.module.expression.model.ExpressionBean;

public class CombinedEvaluatorJUnitTest {

	private CombinedEvaluator evaluator;
	private ExpressionEvaluator expressionEvaluator;
	private CommutationEvaluator commutationEvaluator;
	
	@Before
	public void setUp(){
		expressionEvaluator = mock(ExpressionEvaluator.class);
		commutationEvaluator = mock(CommutationEvaluator.class);
		evaluator = new CombinedEvaluator(expressionEvaluator, commutationEvaluator);
	}
	
	@Test
	public void expressionIsWrong() {
		// given
		ExpressionBean bean = mock(ExpressionBean.class);
		stub(expressionEvaluator.evaluate(any(ExpressionBean.class))).toReturn(false);
		
		// when
		evaluator.evaluate(bean);
		
		// then
		verify(expressionEvaluator).evaluate(eq(bean));
		verify(commutationEvaluator, never()).evaluate(eq(bean));
	}
	
	@Test
	public void expressionIsCorrect() {
		// given
		ExpressionBean bean = mock(ExpressionBean.class);
		stub(expressionEvaluator.evaluate(any(ExpressionBean.class))).toReturn(true);
		
		// when
		evaluator.evaluate(bean);
		
		// then
		verify(expressionEvaluator).evaluate(eq(bean));
		verify(commutationEvaluator).evaluate(eq(bean));
	}

}

@@ -57,24 +57,124 @@
 valuate;%0D%0A%0D%0A
+import static org.hamcrest.MatcherAssert.assertThat;%0D%0Aimport static org.hamcrest.Matchers.equalTo;%0D%0A
 import stati
@@ -202,16 +202,16 @@
 s.any;%0D%0A
-
 import s
@@ -408,16 +408,87 @@
 verify;%0D
+%0Aimport junitparams.JUnitParamsRunner;%0D%0Aimport junitparams.Parameters;%0D
 %0A%0D%0Aimpor
@@ -531,16 +531,50 @@
 t.Test;%0D
+%0Aimport org.junit.runner.RunWith;%0D
 %0A%0D%0Aimpor
@@ -647,16 +647,51 @@
 ean;%0D%0A%0D%0A
+@RunWith(JUnitParamsRunner.class)%0D%0A
 public c
@@ -1125,32 +1125,49 @@
 t%0D%0A%09public void 
+checkCommutation_
 expressionIsWron
@@ -1519,16 +1519,33 @@
 ic void 
+checkCommutation_
 expressi
@@ -1809,32 +1809,32 @@
 ate(eq(bean));%0D%0A
-
 %09%09verify(commuta
@@ -1872,14 +1872,931 @@
 ));%0D%0A%09%7D%0D
+%0A%09%0D%0A%09@Test%0D%0A%09public void result_correct() %7B%0D%0A%09%09// given%0D%0A%09%09ExpressionBean bean = mock(ExpressionBean.class);%0D%0A%09%09stub(expressionEvaluator.evaluate(any(ExpressionBean.class))).toReturn(true);%0D%0A%09%09stub(commutationEvaluator.evaluate(any(ExpressionBean.class))).toReturn(true);%0D%0A%09%09%0D%0A%09%09// when%0D%0A%09%09boolean result = evaluator.evaluate(bean);%0D%0A%09%09%0D%0A%09%09// then%0D%0A%09%09assertThat(result, equalTo(true));%0D%0A%09%7D%0D%0A%09%0D%0A%09@Test%0D%0A%09@Parameters(%7B%22false, true%22, %22true, false%22, %22false, false%22%7D)%0D%0A%09public void result_wrong(boolean expressionResult, boolean commutationResult) %7B%0D%0A%09%09// given%0D%0A%09%09ExpressionBean bean = mock(ExpressionBean.class);%0D%0A%09%09stub(expressionEvaluator.evaluate(any(ExpressionBean.class))).toReturn(expressionResult);%0D%0A%09%09stub(commutationEvaluator.evaluate(any(ExpressionBean.class))).toReturn(commutationResult);%0D%0A%09%09%0D%0A%09%09// when%0D%0A%09%09boolean result = evaluator.evaluate(bean);%0D%0A%09%09%0D%0A%09%09// then%0D%0A%09%09assertThat(result, equalTo(false));%0D%0A%09%7D%0D
 %0A%0D%0A%7D%0D%0A

add result test for combined evaluator issue YPUB-5354