package cli.category;

import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

class CategoryCommandsTest {

	CategoryCliAdapter mockAdapter = mock(CategoryCliAdapter.class);

	@Test
	void addCommandWorks() {
		var categoryName = "funStuff";
		ArgumentCaptor<String> valueCapture = ArgumentCaptor.forClass(String.class);
		doNothing().when(mockAdapter).addCategory(valueCapture.capture());
		var sut = new CategoryCommands(mockAdapter);

		var returnValue = sut.executeSubcommand(new String[]{"add", categoryName});

		assertEquals(categoryName, valueCapture.getValue());
		assertEquals("Added the new category", returnValue);
	}

	@Test
	void getCommandWorks() {
		var sut = new CategoryCommands(mockAdapter);
		when(mockAdapter.getCategories()).thenReturn(Set.of("funStuff", "workStuff"));
		var returnValue = sut.executeSubcommand(new String[]{"get"});

		var expected =
				"Available Categories:" + System.lineSeparator() + "funStuff" + System.lineSeparator() + "workStuff";

		var expectedDifferentOrder =
				"Available Categories:" + System.lineSeparator() + "workStuff" + System.lineSeparator() + "funStuff";
		assertTrue(expected.equals(returnValue) || expectedDifferentOrder.equals(returnValue));
	}
}
