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);
	}

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

		int numberOfEntries = report.getEntries().size();
		assertEquals("There should be no result, but was " + numberOfEntries,
				0, numberOfEntries);
	}

}

@@ -697,21 +697,22 @@
 ployment
+/
 %22));%0A
-
 %09%09int de
@@ -1029,32 +1029,33 @@
 ty/server/simple
+/
 %22));%0A%0A%09%09String a
@@ -1405,16 +1405,17 @@
 r/simple
+/
 %22));%0A%0A%09%09
@@ -1791,16 +1791,17 @@
 advanced
+/
 %22));%0A%0A%09%09
@@ -2109,32 +2109,32 @@
 ths.get(userDir%0A
-
 %09%09%09%09+ %22/src/test
@@ -2171,16 +2171,17 @@
 er/empty
+/
 %22));%0A%0A%09%09

Append / to dir names