// Path: src/main/java/se/gustavkarlsson/rocketchat/jira_trigger/server/Server.java
// public class Server {
// 	private static final Logger log = getLogger(Server.class);
// 
// 	public static final long MAX_PORT_NUMBER = 65535;
// 	private static final String APPLICATION_JSON = "application/json";
// 
// 	private final int maxThreads;
// 	private final String ipAddress;
// 	private final int port;
// 	private final DetectIssueRoute detectIssueRoute;
// 	private final JiraServerInfoLogger jiraServerInfoLogger;
// 
// 	private Service service;
// 
// 	Server(int maxThreads, String ipAddress, int port, DetectIssueRoute detectIssueRoute, JiraServerInfoLogger jiraServerInfoLogger) {
// 		this.maxThreads = maxThreads;
// 		inclusiveBetween(1, Integer.MAX_VALUE, maxThreads);
// 		this.ipAddress = notBlank(ipAddress);
// 		this.port = port;
// 		inclusiveBetween(1, MAX_PORT_NUMBER, port);
// 		this.detectIssueRoute = notNull(detectIssueRoute);
// 		this.jiraServerInfoLogger = notNull(jiraServerInfoLogger);
// 	}
// 
// 	private static void logRequest(Request request) {
// 		log.info("Incoming request: {} {} {} {}",
// 				request.raw().getRemoteAddr(), request.requestMethod(), request.contentType(), request.pathInfo());
// 	}
// 
// 	private static void logResponse(Response response) {
// 		String responseContent = response.body() == null ? "<empty>" : "Rocket.Chat message";
// 		log.info("Outgoing response: {}", responseContent);
// 	}
// 
// 	public synchronized void start() {
// 		jiraServerInfoLogger.logInfo();
// 		log.info("Starting server...");
// 		if (service != null) {
// 			throw new IllegalStateException("Already started");
// 		}
// 		Service service = ignite();
// 		service.threadPool(maxThreads);
// 		service.port(port);
// 		service.ipAddress(ipAddress);
// 		service.before((request, response) -> logRequest(request));
// 		service.post("/", APPLICATION_JSON, detectIssueRoute);
// 		service.after((request, response) -> logResponse(response));
// 		service.exception(Exception.class, new UuidGeneratingExceptionHandler());
// 		this.service = service;
// 	}
// 
// 	public synchronized void stop() {
// 		if (service == null) {
// 			throw new IllegalStateException("Already stopped");
// 		}
// 		service.stop();
// 		service = null;
// 	}
// }
// 
// Path: src/main/java/se/gustavkarlsson/rocketchat/jira_trigger/configuration/AppConfiguration.java
// @Singleton
// public class AppConfiguration {
// 	private static final String KEY_PREFIX = "app.";
// 	static final String IP_ADDRESS_KEY = KEY_PREFIX + "ip_address";
// 	static final String PORT_KEY = KEY_PREFIX + "port";
// 	static final String MAX_THREADS_KEY = KEY_PREFIX + "max_threads";
// 
// 	private final String ipAddress;
// 	private final int port;
// 	private final int maxThreads;
// 
// 	@Inject
// 	AppConfiguration(ConfigMap configMap) throws ValidationException {
// 		notNull(configMap);
// 		try {
// 			ipAddress = notBlank(configMap.getString(IP_ADDRESS_KEY), String.format("Non-blank %s must be provided", IP_ADDRESS_KEY));
// 			port = notNull(configMap.getLong(PORT_KEY), String.format("%s must be provided", PORT_KEY)).intValue();
// 			inclusiveBetween(1, Server.MAX_PORT_NUMBER, port, String.format("%s must be within %d and %d. Was: %d", PORT_KEY, 1, Server.MAX_PORT_NUMBER, port));
// 			maxThreads = notNull(configMap.getLong(MAX_THREADS_KEY), String.format("%s must be provided", MAX_THREADS_KEY)).intValue();
// 			inclusiveBetween(1, Integer.MAX_VALUE, maxThreads, String.format("%s must be within %d and %d. Was: %d", MAX_THREADS_KEY, 1, Integer.MAX_VALUE, maxThreads));
// 		} catch (Exception e) {
// 			throw new ValidationException(e);
// 		}
// 	}
// 
// 	public String getIpAddress() {
// 		return ipAddress;
// 	}
// 
// 	public int getPort() {
// 		return port;
// 	}
// 
// 	public int getMaxThreads() {
// 		return maxThreads;
// 	}
// }


import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import se.gustavkarlsson.rocketchat.jira_trigger.server.Server;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import static se.gustavkarlsson.rocketchat.jira_trigger.configuration.AppConfiguration.*;

	@Test(expected = ValidationException.class)
	public void createWithNullIpThrowsValidationException() throws Exception {
		when(mockConfigMap.getString(IP_ADDRESS_KEY)).thenReturn(null);

		new AppConfiguration(mockConfigMap);
	}

	@Test(expected = ValidationException.class)
	public void createBlankIpThrowsValidationException() throws Exception {
		when(mockConfigMap.getString(IP_ADDRESS_KEY)).thenReturn(" \t\n");

		new AppConfiguration(mockConfigMap);
	}

	@Test(expected = ValidationException.class)
	public void createWithTooHighPortThrowsValidationException() throws Exception {
		when(mockConfigMap.getLong(PORT_KEY)).thenReturn(Server.MAX_PORT_NUMBER + 1);

		new AppConfiguration(mockConfigMap);
	}

	@Test(expected = ValidationException.class)
	public void createWithTooLowPortThrowsValidationException() throws Exception {
		when(mockConfigMap.getLong(PORT_KEY)).thenReturn(0L);

		new AppConfiguration(mockConfigMap);
	}

	@Test
// Path: src/main/java/se/gustavkarlsson/rocketchat/jira_trigger/server/Server.java
// public class Server {
// 	private static final Logger log = getLogger(Server.class);
// 
// 	public static final long MAX_PORT_NUMBER = 65535;
// 	private static final String APPLICATION_JSON = "application/json";
// 
// 	private final int maxThreads;
// 	private final String ipAddress;
// 	private final int port;
// 	private final DetectIssueRoute detectIssueRoute;
// 	private final JiraServerInfoLogger jiraServerInfoLogger;
// 
// 	private Service service;
// 
// 	Server(int maxThreads, String ipAddress, int port, DetectIssueRoute detectIssueRoute, JiraServerInfoLogger jiraServerInfoLogger) {
// 		this.maxThreads = maxThreads;
// 		inclusiveBetween(1, Integer.MAX_VALUE, maxThreads);
// 		this.ipAddress = notBlank(ipAddress);
// 		this.port = port;
// 		inclusiveBetween(1, MAX_PORT_NUMBER, port);
// 		this.detectIssueRoute = notNull(detectIssueRoute);
// 		this.jiraServerInfoLogger = notNull(jiraServerInfoLogger);
// 	}
// 
// 	private static void logRequest(Request request) {
// 		log.info("Incoming request: {} {} {} {}",
// 				request.raw().getRemoteAddr(), request.requestMethod(), request.contentType(), request.pathInfo());
// 	}
// 
// 	private static void logResponse(Response response) {
// 		String responseContent = response.body() == null ? "<empty>" : "Rocket.Chat message";
// 		log.info("Outgoing response: {}", responseContent);
// 	}
// 
// 	public synchronized void start() {
// 		jiraServerInfoLogger.logInfo();
// 		log.info("Starting server...");
// 		if (service != null) {
// 			throw new IllegalStateException("Already started");
// 		}
// 		Service service = ignite();
// 		service.threadPool(maxThreads);
// 		service.port(port);
// 		service.ipAddress(ipAddress);
// 		service.before((request, response) -> logRequest(request));
// 		service.post("/", APPLICATION_JSON, detectIssueRoute);
// 		service.after((request, response) -> logResponse(response));
// 		service.exception(Exception.class, new UuidGeneratingExceptionHandler());
// 		this.service = service;
// 	}
// 
// 	public synchronized void stop() {
// 		if (service == null) {
// 			throw new IllegalStateException("Already stopped");
// 		}
// 		service.stop();
// 		service = null;
// 	}
// }
// 
// Path: src/main/java/se/gustavkarlsson/rocketchat/jira_trigger/configuration/AppConfiguration.java
// @Singleton
// public class AppConfiguration {
// 	private static final String KEY_PREFIX = "app.";
// 	static final String IP_ADDRESS_KEY = KEY_PREFIX + "ip_address";
// 	static final String PORT_KEY = KEY_PREFIX + "port";
// 	static final String MAX_THREADS_KEY = KEY_PREFIX + "max_threads";
// 
// 	private final String ipAddress;
// 	private final int port;
// 	private final int maxThreads;
// 
// 	@Inject
// 	AppConfiguration(ConfigMap configMap) throws ValidationException {
// 		notNull(configMap);
// 		try {
// 			ipAddress = notBlank(configMap.getString(IP_ADDRESS_KEY), String.format("Non-blank %s must be provided", IP_ADDRESS_KEY));
// 			port = notNull(configMap.getLong(PORT_KEY), String.format("%s must be provided", PORT_KEY)).intValue();
// 			inclusiveBetween(1, Server.MAX_PORT_NUMBER, port, String.format("%s must be within %d and %d. Was: %d", PORT_KEY, 1, Server.MAX_PORT_NUMBER, port));
// 			maxThreads = notNull(configMap.getLong(MAX_THREADS_KEY), String.format("%s must be provided", MAX_THREADS_KEY)).intValue();
// 			inclusiveBetween(1, Integer.MAX_VALUE, maxThreads, String.format("%s must be within %d and %d. Was: %d", MAX_THREADS_KEY, 1, Integer.MAX_VALUE, maxThreads));
// 		} catch (Exception e) {
// 			throw new ValidationException(e);
// 		}
// 	}
// 
// 	public String getIpAddress() {
// 		return ipAddress;
// 	}
// 
// 	public int getPort() {
// 		return port;
// 	}
// 
// 	public int getMaxThreads() {
// 		return maxThreads;
// 	}
// }


// Path: src/test/java/se/gustavkarlsson/rocketchat/jira_trigger/configuration/AppConfigurationTest.java
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import se.gustavkarlsson.rocketchat.jira_trigger.server.Server;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import static se.gustavkarlsson.rocketchat.jira_trigger.configuration.AppConfiguration.*;


	@Test(expected = ValidationException.class)
	public void createWithNullIpThrowsValidationException() throws Exception {
		when(mockConfigMap.getString(IP_ADDRESS_KEY)).thenReturn(null);

		new AppConfiguration(mockConfigMap);
	}

	@Test(expected = ValidationException.class)
	public void createBlankIpThrowsValidationException() throws Exception {
		when(mockConfigMap.getString(IP_ADDRESS_KEY)).thenReturn(" \t\n");

		new AppConfiguration(mockConfigMap);
	}

	@Test(expected = ValidationException.class)
	public void createWithTooHighPortThrowsValidationException() throws Exception {
		when(mockConfigMap.getLong(PORT_KEY)).thenReturn(Server.MAX_PORT_NUMBER + 1);

		new AppConfiguration(mockConfigMap);
	}

	@Test(expected = ValidationException.class)
	public void createWithTooLowPortThrowsValidationException() throws Exception {
		when(mockConfigMap.getLong(PORT_KEY)).thenReturn(0L);

		new AppConfiguration(mockConfigMap);
	}

	@Test
	public void createWithLowestPortSucceeds() throws Exception {