package tests;

import static org.junit.Assert.*;

import java.util.Random;

import org.mockito.*;
import org.junit.Test;

import StarTrek.*;
import Untouchables.WebGadget;

public class CharacterizationTestExample {

	/*
	 * samples-java-junit/MessTrek: a solution to labs-java-junit/MessTrek
	 * using Mockito.
	 * 
	 * This is not a unit test.  This is what you get when you try to
	 * do unit testing of code that has grown without using TDD.
	 * It's a characterization test, which replicates an existing scenario.
	 * 
	 * This is only one of about 9 scenarios which would need to be tested
	 * before you could safely refactor this code.
	 * 
	 * If you want to practice refactoring,
	 * see labs-java-junit/TestedTrek
	 */
	@Test
	public void testWhenPhotonsDamageKlingon() {
		// given
		Game game = new Game();
		
		Random mockRandom = Mockito.mock(Random.class);
		Mockito.when(mockRandom.nextInt(Mockito.anyInt())).thenReturn(2);
		Game.generator = mockRandom;
		
		Klingon target = Mockito.mock(Klingon.class);
		Mockito.when(target.distance())
			.thenReturn(365);
		// let's make the mock Klingon ignore setEnergy(). Just for fun.
		Mockito.when(target.getEnergy())
			.thenReturn(2000)
			.thenReturn(42);

		ProxyWebGadget mockProxyWebGadget = Mockito.mock(ProxyWebGadget.class);
		Mockito.when(mockProxyWebGadget.parameter("command"))
			.thenReturn("photon");
		Mockito.when(mockProxyWebGadget.variable("target"))
			.thenReturn(target);
		
		// when
		game.fireWeapon(mockProxyWebGadget);
		
		// then
		assertEquals(7, game.torpedoesRemaining());
		Mockito.verify(target, Mockito.never()).delete();
		Mockito.verify(mockProxyWebGadget,
				Mockito.times(1)).writeLine(
						"Photons hit Klingon at 365 sectors with 802 units");
		Mockito.verify(mockProxyWebGadget,
				Mockito.times(1)).writeLine(
						"Klingon has 42 remaining");
	}

}

@@ -1078,146 +1078,266 @@
 ;%0A%09%09
-// let's make the mock Klingon ignore setEnergy(). Just for fun.%0A%09%09Mockito.when(target.getEnergy())%0A%09%09%09.thenReturn(2000)%0A%09%09%09.thenReturn(42
+int klingonInitialEnergy = 2000;%0A%09%09int klingonEnergyRemainingAfterDamage = klingonInitialEnergy-802;%0A%09%09Mockito.when(target.getEnergy())%0A%09%09%09.thenReturn(klingonInitialEnergy)%0A%09%09%09.thenReturn(klingonInitialEnergy)%0A%09%09%09.thenReturn(klingonEnergyRemainingAfterDamage
 );%0A%0A
@@ -1733,16 +1733,105 @@
 lete();%0A
+%09%09Mockito.verify(target, Mockito.times(1)).setEnergy(klingonEnergyRemainingAfterDamage);%0A
 %09%09Mockit
@@ -2045,10 +2045,12 @@
 has 
-42
+1198
  rem

Improve behavioral coverage