package com.github.aureliano.evtbridge.app.helper;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.github.aureliano.evtbridge.app.command.HelpCommand;
import com.github.aureliano.evtbridge.app.command.ICommand;
import com.github.aureliano.evtbridge.app.command.VersionCommand;

import joptsimple.OptionParser;
import joptsimple.OptionSet;

public class CliHelperTest {

	@Test
	public void testSupportedFileTypes() {
		String expected = "json, yaml";
		String actual = CliHelper.supportedFileTypes();
		
		assertEquals(expected, actual);
	}
	
	@Test
	public void testBuildOptionSet() {
		this._assertCliOption("h", "help");
		this._assertCliOption("v", "version");
	}
	
	@Test
	public void testBuildCommand() {
		OptionParser parser = CliHelper.parseOptions();
		OptionSet options = parser.parse(new String[0]);
		ICommand command = CliHelper.buildCommand(new String[0], options);
		assertNull(command);
		
		options = parser.parse(new String[] { "-h" });
		command = CliHelper.buildCommand(new String[0], options);
		assertTrue(command instanceof HelpCommand);
		
		options = parser.parse(new String[] { "-v" });
		command = CliHelper.buildCommand(new String[0], options);
		assertTrue(command instanceof VersionCommand);
	}
	
	private void _assertCliOption(String shortcut, String option) {
		OptionParser parser = CliHelper.parseOptions();
		OptionSet options = parser.parse(new String[] { "-" + shortcut });
		assertTrue(options.has(option));
		
		options = parser.parse(new String[] { "--" + option });
		assertTrue(options.has(option));
	}
}
@@ -316,32 +316,99 @@
 mmand.ICommand;%0A
+import com.github.aureliano.evtbridge.app.command.SchemataCommand;%0A
 import com.githu
@@ -457,16 +457,16 @@
 ommand;%0A
-
 %0Aimport 
@@ -845,16 +845,58 @@
 sion%22);%0A
+%09%09this._assertCliOption(%22s%22, %22schemata%22);%0A
 %09%7D%0A%09%0A%09@T
@@ -1388,32 +1388,32 @@
 g%5B0%5D, options);%0A
-
 %09%09assertTrue(com
@@ -1445,16 +1445,178 @@
 mmand);%0A
+%09%09%0A%09%09options = parser.parse(new String%5B%5D %7B %22-s%22 %7D);%0A%09%09command = CliHelper.buildCommand(new String%5B0%5D, options);%0A%09%09assertTrue(command instanceof SchemataCommand);%0A
 %09%7D%0A%09%0A%09pr

Test schemata cli parameter availability.