package edu.iis.mto.serverloadbalancer;

import static edu.iis.mto.serverloadbalancer.CurrentLoadPercentageMatcher.hasLoadPercentageOf;
import static edu.iis.mto.serverloadbalancer.ServerBuilder.server;
import static edu.iis.mto.serverloadbalancer.VmBuilder.vm;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

import org.junit.Test;

public class ServerLoadBalancerTest {
	@Test
	public void itCompiles() {
		assertThat(true, equalTo(true));
	}

	@Test
	public void balancingAServer_noVms_serverStaysEmpty() {
		Server theServer = a(server().withCapacity(1));

		balance(aListOfServersWith(theServer), anEmptyListOfVms());

		assertThat(theServer, hasLoadPercentageOf(0.0d));
	}

	@Test
	public void balancingOneServerWithOneSlotCapacity_andOneSlotVm_fillsTheServerWithTheVm() {
		Server theServer = a(server().withCapacity(1));
		Vm theVm = a(vm().ofSize(1));
		balance(aListOfServersWith(theServer), aListOfVmsWith(theVm));

		assertThat(theServer, hasLoadPercentageOf(100.0d));
		assertThat("the server should contain vm", theServer.contains(theVm));
	}

	private void balance(Server[] servers, Vm[] vms) {
		new ServerLoadBalancer().balance(servers, vms);
	}

	private Vm[] aListOfVmsWith(Vm vm) {
		return new Vm[] { vm };
	}

	private Vm[] anEmptyListOfVms() {
		return new Vm[0];
	}

	private Server[] aListOfServersWith(Server server) {
		return new Server[] { server };
	}

	private <T> T a(Builder<T> builder) {
		return builder.build();
	}
}

@@ -1098,24 +1098,411 @@
 heVm));%0A%09%7D%0A%0A
+%09@Test %0A%09public void balancingOneServerWithTenSlotsCapacity_andOneSlotVm_fillTheServerWithTenPercent()%7B%0A%09%09Server theServer = a(server().withCapacity(10));%0A%09%09Vm theVm = a(vm().ofSize(1));%0A%09%09balance(aListOfServersWith(theServer), aListOfVmsWith(theVm));%0A%0A%09%09assertThat(theServer, hasLoadPercentageOf(10.0d));%0A%09%09assertThat(%22the server should contain vm%22, theServer.contains(theVm));%0A%09%09%0A%09%7D%0A%09%0A
 %09private voi

test 3 red