package pipe.views;

import static org.junit.Assert.*;

import java.awt.Color;
import java.util.Observable;
import java.util.Observer;

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

import pipe.models.PipeObservable;
import pipe.models.component.token.Token;

public class MarkingViewTest implements Observer
{
	private MarkingView markingView;
	private TokenView tokenView;
	private boolean called;
	private boolean newMarkingViewShouldBeNull;

	@Before
	public void setUp() throws Exception
	{
		tokenView = new TokenView(true, "Fred", Color.black); 
	}
	@Test
	public void verifyTokenViewCanBeReplacedWithNewInstance() throws Exception
	{
		Token model = tokenView.getModel(); 
		markingView = new MarkingView(tokenView, 3); 
		assertEquals("Fred", markingView.getToken().getID()); 
		TokenView newTokenView = new TokenView(true, "Mary", Color.green); 
		newTokenView.updateModelFromPrevious(tokenView); 
		assertEquals(newTokenView, markingView.getToken()); 
		assertEquals("Mary", markingView.getToken().getID()); 
		assertEquals(Color.green, markingView.getToken().getColor()); 
		assertEquals(model, markingView.getToken().getModel()); 
	}
	@Test
	public void verifyTokenViewThatIsLaterDisabledGeneratesNullUpdate() throws Exception
	{
		markingView = new MarkingView(tokenView, 3); 
		assertEquals(tokenView, markingView.getToken()); 
		tokenView.disableAndNotifyObservers(); 
		assertNull(markingView.getToken()); 
	}
	@Test
	public void verifyMarkingViewTellsObserversToDeleteSelfIfItsTokenViewIsSetDisabled() throws Exception
	{
		markingView = new MarkingView(tokenView, 3); 
		markingView.addObserver(this); 
		newMarkingViewShouldBeNull = true; 
		markingView.setChanged();
		markingView.notifyObservers(null); 
		while (!called)
		{
			Thread.sleep(10);
		}	
	}
	@Override
	public void update(Observable oldObject, Object newObject)
	{
		called = true;
		MarkingView view=null; 
		if (oldObject instanceof PipeObservable)
		{
			view = (MarkingView) ((PipeObservable) oldObject).getObservable();
		}
		assertEquals(view , markingView); 
		if (newMarkingViewShouldBeNull)  assertNull(newObject);
	}

}

@@ -1427,358 +1427,8 @@
 %0A%09%7D%0A
-%09@Test%0A%09public void verifyMarkingViewTellsObserversToDeleteSelfIfItsTokenViewIsSetDisabled() throws Exception%0A%09%7B%0A%09%09markingView = new MarkingView(tokenView, 3); %0A%09%09markingView.addObserver(this); %0A%09%09newMarkingViewShouldBeNull = true; %0A%09%09markingView.setChanged();%0A%09%09markingView.notifyObservers(null); %0A%09%09while (!called)%0A%09%09%7B%0A%09%09%09Thread.sleep(10);%0A%09%09%7D%09%0A%09%7D%0A
 %09@Ov

Remove buggy unit test