package org.sagebionetworks.web.unitclient.utils;

import static org.mockito.Mockito.*;

import org.junit.Before;
import org.junit.Test;
import org.sagebionetworks.web.client.utils.AnimationProtector;
import org.sagebionetworks.web.client.utils.AnimationProtectorView;

import com.extjs.gxt.ui.client.Style.Direction;
import com.extjs.gxt.ui.client.fx.FxConfig;
import com.google.gwt.event.dom.client.ClickHandler;

public class AnimationProtectorTest {

	private AnimationProtector animation;
	private AnimationProtectorView mockView;

	@Before
	public void setup() {
		mockView = mock(AnimationProtectorView.class);
		when(mockView.isContainerRendered()).thenReturn(true);
		animation = new AnimationProtector(mockView);
		verify(mockView).addClickHandler((ClickHandler)any());
	}

	@Test
	public void testShowVisible() {
		setViewVisible(true);
		animation.show();
		verifyNoSlides();
	}

	@Test
	public void testShowHidden() {
		setViewVisible(false);
		animation.show();
		verifyShown();
	}

	@Test
	public void testHideVisible() {
		setViewVisible(true);
		animation.hide();
		verifyHidden();
	}

	@Test
	public void testHideHidden() {
		setViewVisible(false);
		animation.hide();
		verifyNoSlides();
	}

	@Test
	public void testToggleVisible() {
		setViewVisible(true);
		animation.toggle();
		verifyHidden();
	}

	@Test
	public void testToggleHidden() {
		setViewVisible(false);
		animation.toggle();
		verifyShown();
	}

	private void setViewVisible(boolean setVisible) {
		when(mockView.isContainerVisible()).thenReturn(setVisible);
	}

	private void verifyNoSlides() {
		verify(mockView, times(0)).slideContainerIn((Direction)any(), (FxConfig)any());
		verify(mockView, times(0)).slideContainerOut((Direction)any(), (FxConfig)any());
	}

	private void verifyHidden() {
		// SlideOut actually means to hide
		verify(mockView).slideContainerOut((Direction)any(), (FxConfig)any());
	}

	private void verifyShown() {
		// SlideIn actually means to show
		verify(mockView).setContainerVisible(eq(true));
		verify(mockView).slideContainerIn((Direction)any(), (FxConfig)any());
	}
}

@@ -82,16 +82,49 @@
 ito.*;%0A%0A
+import java.lang.reflect.Field;%0A%0A
 import o
@@ -1452,24 +1452,550 @@
 hown();%0A%09%7D%0A%0A
+%09@Test%0A%09public void testAnimationToggle() throws SecurityException,%0A%09%09%09NoSuchFieldException, IllegalArgumentException,%0A%09%09%09IllegalAccessException %7B%0A%09%09Class%3C? extends AnimationProtector%3E clazz = animation.getClass();%0A%09%09Field field = clazz.getDeclaredField(%22animating%22);%0A%09%09field.setAccessible(true);%0A%09%09field.set(animation, true);%0A%0A%09%09setViewVisible(true);%0A%09%09animation.toggle();%0A%09%09animation.hide();%0A%09%09animation.show();%0A%09%09setViewVisible(false);%0A%09%09animation.toggle();%0A%09%09animation.hide();%0A%09%09animation.show();%0A%0A%09%09verifyNoSlides();%0A%09%7D%0A%0A
 %09private voi
@@ -2143,39 +2143,38 @@
 erify(mockView, 
-times(0
+never(
 )).slideContaine
@@ -2236,15 +2236,14 @@
 ew, 
-times(0
+never(
 )).s

Add animating flag test