### Question:
MethodOverrideHandler implements HttpHandler { @Override public void handleRequest(HttpServerExchange exchange) throws Exception { if (Methods.POST.equals(exchange.getRequestMethod())) { String newMethod = exchange.getRequestHeaders().getFirst(HEADER); Optional<HttpString> opt = HttpMethod.find(newMethod); if (opt.isPresent()) { exchange.setRequestMethod(opt.get()); } else { FormData data = exchange .getAttachment(FormDataParser.FORM_DATA); if (data != null) { FormData.FormValue fv = data.getFirst(FORM); if (fv != null && fv.isFile() == false) { HttpMethod.find(fv.getValue()).map( exchange::setRequestMethod); } } } } this.next.handleRequest(exchange); } MethodOverrideHandler(HttpHandler next); @Override void handleRequest(HttpServerExchange exchange);  }### Answer:
@Test public void testNotOverride() throws Exception { HttpServerExchange exchange = new MockUp<HttpServerExchange>() { @Mock public HeaderMap getRequestHeaders() { throw new AssertionError(); } @Mock public <T> T getAttachment(final AttachmentKey<T> key) { throw new AssertionError(); } }.getMockInstance(); exchange.setRequestMethod(Methods.GET); this.target.handleRequest(exchange); }
@Test public void testOverrideFromHeader() throws Exception { HttpServerExchange exchange = new HttpServerExchange(null); exchange.setRequestMethod(Methods.POST); exchange.getRequestHeaders().put(MethodOverrideHandler.HEADER, "CONNECT"); this.target.handleRequest(exchange); assertEquals(Methods.CONNECT, exchange.getRequestMethod()); }
@Test public void testOverrideFromForm() throws Exception { HttpServerExchange exchange = new HttpServerExchange(null); exchange.setRequestMethod(Methods.POST); FormData fd = new FormData(3); fd.add(MethodOverrideHandler.FORM, "PUT"); exchange.putAttachment(FormDataParser.FORM_DATA, fd); this.target.handleRequest(exchange); assertEquals(Methods.PUT, exchange.getRequestMethod()); }