package de.baumato.loc;

import static org.assertj.core.api.Assertions.assertThat;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.Before;
import org.junit.Test;

import com.github.javaparser.JavaParser;

import de.baumato.loc.configuration.Configuration;
import de.baumato.loc.printer.ConsolePrinter;

public class LineCounterTest {

	private final Path unformatted = Paths.get("src/test/resources/SomeClass.unformatted.java");
	private final Path formatted = Paths.get("src/test/resources/SomeClass.formatted.java");

	private LineCounter lc;

	@Before
	public void setup() {
		lc = new LineCounter(new Configuration(), new ConsolePrinter());
	}

	@Test
	public void shouldReadJavaFileAfterApplyingDefaultFormatter() throws Exception {
		String expected = JavaParser.parse(unformatted).toString();
		String actual = new String(Files.readAllBytes(formatted));
		assertThat(actual).isEqualTo(expected);
	}

	@Test
	public void shouldReadJavaFileAfterApplyingDefaultFormatter2() throws Exception {
		long uc = lc.countLines(unformatted);
		long fc = lc.countLines(formatted);
		assertThat(uc).isEqualTo(fc).isEqualTo(31);
	}

	@Test
	public void shouldCountJavaFilesOnly() throws Exception {
		Path p = Paths.get("src/test/resources/container/dir");
		lc = new LineCounter(Configuration.ofCmdLine("-d", p.toString()), new ConsolePrinter());
		assertThat(lc.count()).isZero();
	}

	@Test
	public void shouldCount() throws Exception {
		Path p = Paths.get("src/test/resources/container");
		lc = new LineCounter(Configuration.ofCmdLine("-d", p.toString()), new ConsolePrinter());
		assertThat(lc.count()).isEqualTo(31);
	}
}

@@ -1666,11 +1666,302 @@
 (31);%0A%09%7D
+%0A%0A%09@Test%0A%09public void shouldExcludeFoldersSpecifiedInConfiguration() throws Exception %7B%0A%09%09Path p = Paths.get(%22src/test/resources%22);%0A%09%09lc = new LineCounter(%0A%09%09%09Configuration.ofCmdLine(%22-d%22, p.toString(), %22-e%22, %22container%22),%0A%09%09%09new ConsolePrinter());%0A%09%09assertThat(lc.count()).isEqualTo(62);%0A%09%7D
 %0A%7D%0A

test folder exclusions