package test.pete.executables;

import static org.junit.Assert.assertEquals;

import java.nio.file.Paths;

import org.junit.Test;

import pete.executables.DirectoryAnalyzer;
import pete.metrics.installability.deployability.DeploymentPackageAnalyzer;
import pete.metrics.installability.server.AverageInstallationTimeCalculator;
import pete.reporting.Report;

public class DirectoryAnalyzerTests {

	private DirectoryAnalyzer sut;

	private String userDir = System.getProperty("user.dir");

	@Test
	public void testDeployability() {
		sut = new DirectoryAnalyzer(new DeploymentPackageAnalyzer());
		Report report = sut.analyzeDirectory(Paths.get(userDir
				+ "/src/test/resources/installability/deployment"));
		int de = report.getSummedVariable("DE");
		assertEquals("DE should be 214, but was " + de, 214, de);
	}

	@Test
	public void testAITComputation() {
		sut = new DirectoryAnalyzer(new AverageInstallationTimeCalculator());
		Report report = sut.analyzeDirectory(Paths.get(userDir
				+ "/src/test/resources/installability/server/simple"));

		String ait = report.getEntries().get(0).getVariableValue("AIT");
		assertEquals("AIT should be 22,00, but was ", "22,00", ait);
	}

	@Test
	public void testESRComputation() {
		sut = new DirectoryAnalyzer(new AverageInstallationTimeCalculator());
		Report report = sut.analyzeDirectory(Paths.get(userDir
				+ "/src/test/resources/installability/server/simple"));

		String esr = report.getEntries().get(0).getVariableValue("ESR");
		assertEquals("ESR should be 1,00, but was " + esr, "1,00", esr);
	}

	@Test
	public void testOnlyRelevantFilesAreListed() {
		sut = new DirectoryAnalyzer(new AverageInstallationTimeCalculator());
		Report report = sut.analyzeDirectory(Paths.get(userDir
				+ "/src/test/resources/installability/server/advanced"));

		int numberOfEntries = report.getEntries().size();
		assertEquals("Should only list one file, but was " + numberOfEntries,
				1, numberOfEntries);
	}

}

@@ -1947,10 +1947,389 @@
 s);%0A%09%7D%0A%0A
+%09@Test%0A%09public void testEmptyDir() %7B%0A%09%09sut = new DirectoryAnalyzer(new AverageInstallationTimeCalculator());%0A%09%09Report report = sut.analyzeDirectory(Paths.get(userDir%0A%09%09%09%09+ %22/src/test/resources/installability/server/empty%22));%0A%0A%09%09int numberOfEntries = report.getEntries().size();%0A%09%09assertEquals(%22There should be no result, but was %22 + numberOfEntries,%0A%09%09%09%090, numberOfEntries);%0A%09%7D%0A%0A
 %7D%0A

Add test for emtpy dir