

package com.epam.ta.reportportal.entity.enums;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author <a href="mailto:ihar_kahadouski@epam.com">Ihar Kahadouski</a>
 */
class ActivityEventTypeTest {

	private Map<ActivityEventType, List<String>> allowed;
	private List<String> disallowed;

	@BeforeEach
	void setUp() throws Exception {
		allowed = Arrays.stream(ActivityEventType.values())
				.collect(Collectors.toMap(it -> it,
						it -> Arrays.asList(it.getValue(), it.getValue().toUpperCase(), it.getValue().toLowerCase())
				));
		disallowed = Arrays.asList("bla", null, "", "noSuchActivityEventType");
	}

	@Test
	void fromString() {
		allowed.forEach((key, value) -> value.forEach(val -> {
			final Optional<ActivityEventType> optional = ActivityEventType.fromString(val);
			assertTrue(optional.isPresent());
			assertEquals(key, optional.get());
		}));
		disallowed.forEach(it -> assertFalse(ActivityEventType.fromString(it).isPresent()));
	}
}