package nl.tudelft.dnainator.ui.drawables.strains;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;

import nl.tudelft.dnainator.core.SequenceNode;
import nl.tudelft.dnainator.ui.ColorServer;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

/**
 * Test the drawable class that is used for clusters.
 * This class contains a certain amount of clustered sequencenodes,
 * and will dynamically change its size based on that amount. 
 */
@RunWith(MockitoJUnitRunner.class)
public class ClusterDrawableTest {
	@Mock private ColorServer colorserver;
	@Mock private SequenceNode node;
	
	private ClusterDrawable cluster;
	
	/**
	 * Set up common mocks and variables.
	 */
	@Before
	public void setup() {
		Mockito.when(node.getSource()).thenReturn("1");
	}
	
	/**
	 * Test creation of a cluster with a single node.
	 */
	@Test
	public void testCreate() {
		cluster = new ClusterDrawable(colorserver, Arrays.asList(node));
		
		// CHECKSTYLE.OFF: MagicNumber
		Mockito.verify(colorserver, Mockito.times(1)).getColor("1");
		assertEquals(ClusterDrawable.SINGLE_RADIUS, cluster.getRadius(), .001);
		assertEquals(1, cluster.getClustered().size());
		// CHECKSTYLE.ON: MagicNumber
	}
	
	/**
	 * Test creation of a cluster with a small cluster.
	 */
	@Test
	public void testCreateSmall() {
		cluster = new ClusterDrawable(colorserver, Arrays.asList(node, node, node));
		
		// CHECKSTYLE.OFF: MagicNumber
		Mockito.verify(colorserver, Mockito.times(1)).getColor("1");
		assertEquals(ClusterDrawable.SMALL_RADIUS, cluster.getRadius(), .001);
		assertEquals(3, cluster.getClustered().size());
		// CHECKSTYLE.ON: MagicNumber
	}
	
	/**
	 * Test creation of a cluster with a medium cluster.
	 */
	@Test
	public void testCreateMedium() {
		cluster = new ClusterDrawable(colorserver, Arrays.asList(node, node, node, node));
		
		// CHECKSTYLE.OFF: MagicNumber
		Mockito.verify(colorserver, Mockito.times(1)).getColor("1");
		assertEquals(ClusterDrawable.MEDIUM_RADIUS, cluster.getRadius(), .001);
		assertEquals(4, cluster.getClustered().size());
		// CHECKSTYLE.ON: MagicNumber
	}
	
	/**
	 * Test creation of a cluster with a large cluster.
	 */
	@Test
	public void testCreateLarge() {
		cluster = new ClusterDrawable(colorserver, Arrays.asList(node, node, node, node, node,
									node, node, node, node, node, node));
		
		// CHECKSTYLE.OFF: MagicNumber
		Mockito.verify(colorserver, Mockito.times(1)).getColor("1");
		assertEquals(ClusterDrawable.LARGE_RADIUS, cluster.getRadius(), .001);
		assertEquals(11, cluster.getClustered().size());
		// CHECKSTYLE.ON: MagicNumber
	}
}

@@ -115,16 +115,64 @@
 .Arrays;
+%0Aimport java.util.HashSet;%0Aimport java.util.Set;
 %0A%0Aimport
@@ -895,16 +895,77 @@
 tup() %7B%0A
+%09%09Set%3CString%3E sources = new HashSet%3C%3E();%0A%09%09sources.add(%221%22);%0A
 %09%09Mockit
@@ -985,16 +985,17 @@
 etSource
+s
 ()).then
@@ -1001,19 +1001,23 @@
 nReturn(
-%221%22
+sources
 );%0A%09%7D%0A%09%0A

Fix ClusterDrawableTest: getSource() -> getSources()