GripServer { public void addHandler(Handler handler) { if (!handlers.contains(handler)) { handlers.addHandler(handler); } } @Inject  GripServer(ContextStore contextStore,
             JettyServerFactory serverFactory,
             SettingsProvider settingsProvider); static boolean isPortValid(int port); void addHandler(Handler handler); void removeHandler(Handler handler); void start(); void stop(); void restart(); State getState(); void setPort(int port); int getPort(); @Subscribe void settingsChanged(AppSettingsChangedEvent event); static final String ROOT_PATH; static final String UPLOAD_PATH; static final String IMAGE_UPLOAD_PATH; static final String PIPELINE_UPLOAD_PATH; static final String DATA_PATH; static final int DEFAULT_PORT; }
@Test public void testSuccessfulHandler() throws IOException { String path = "/testSuccessfulHandler"; boolean[] didRun = {false}; Handler h = new TestHandler(path, () -> { didRun[0] = true; }); instance.addHandler(h); doPost(path, path.getBytes(StandardCharsets.UTF_8)); assertTrue("Handler should have run on " + path, didRun[0]); }
@Test public void testUnsuccessfulPostHandler() throws Exception { String path = "/testUnsuccessfulPostHandler"; boolean[] didRun = {false}; Handler h = new TestHandler(path, () -> { didRun[0] = true; throw new GripServerException("Expected"); }); instance.addHandler(h); HttpResponse response = doPost(path, path.getBytes(StandardCharsets.UTF_8)); assertEquals("Server should return an internal error (500)", 500, response.getStatusLine().getStatusCode()); assertTrue("Handler should have run", didRun[0]); }