package spark;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

import static spark.Service.ignite;

public class InitExceptionHandlerTest {

    private static Service service1;
    private static Service service2;
    private static String errorMessage = "";


    @BeforeClass
    public static void setUpClass() throws Exception {

        service1 = ignite();
        service1.port(1122);
        service1.init();
        service1.awaitInitialization();

        service2 = ignite();
        service2.port(1122);
        service2.initExceptionHandler((e) -> errorMessage = "Custom init error");
        service2.init();
        service2.awaitInitialization();

    }

    @Test
    public void testGetPort_withRandomPort() throws Exception {
        Assert.assertEquals("Custom init error", errorMessage);
    }

    @AfterClass
    public static void tearDown() throws Exception {
        service1.stop();
        service2.stop();
    }

}

@@ -218,24 +218,46 @@
 tic 
-Service service1
+int NON_VALID_PORT = Integer.MAX_VALUE
 ;%0A  
@@ -288,17 +288,16 @@
  service
-2
 ;%0A    pr
@@ -336,17 +336,16 @@
  = %22%22;%0A%0A
-%0A
     @Bef
@@ -408,17 +408,16 @@
 ption %7B%0A
-%0A
         
@@ -423,17 +423,16 @@
  service
-1
  = ignit
@@ -455,88 +455,31 @@
 vice
-1
 .port(
-1122);%0A        service1.init();%0A        service1.awaitInitialization(
+NON_VALID_PORT
 );%0A
-%0A
     
@@ -493,67 +493,8 @@
 vice
-2 = ignite();%0A        service2.port(1122);%0A        service2
 .ini
@@ -570,17 +570,16 @@
  service
-2
 .init();
@@ -594,17 +594,16 @@
  service
-2
 .awaitIn
@@ -618,17 +618,16 @@
 tion();%0A
-%0A
     %7D%0A%0A 
@@ -659,30 +659,28 @@
 test
-GetPort_withRandomPort
+InitExceptionHandler
 () t
@@ -856,34 +856,8 @@
 vice
-1.stop();%0A        service2
 .sto

Simplify InitExceptionHandlerTest