// Path: jflask/src/main/java/net/jflask/ErrorHandler.java
// public interface ErrorHandler {
//   /**
//    * Handles an error (either a 404 error due to invalid URL or a 500 error
//    * due to an exception thrown by a handler).
//    *
//    * @param status the request status sent back to client
//    * @param request the request sent by client
//    * @param t optional error (null in case of 404)
//    */
//   void onError(int status, Request request, Throwable t);
// }
// 
// Path: jflask/src/main/java/net/jflask/Request.java
// public interface Request {
// 
//   /**
//    * Returns the part of this request's URL from the protocol name up to the
//    * query string in the first line of the HTTP request.
//    */
//   String getRequestURI();
// 
//   /**
//    * Returns the query string contained in request URL after the path. This
//    * method returns <code>null</code> if the URL does not have a query string.
//    * Same as the value of the CGI variable QUERY_STRING.
//    *
//    * @return a <code>String</code> containing the query string or
//    *         <code>null</code> if the URL contains no query string
//    */
// 
//   String getQueryString();
//   
//   /**
//    * Returns the HTTP verb (GET, POST, etc.) used in the request.
//    */
//   String getMethod();
// 
//   /**
//    * Returns parameter submitted in the query string, eg. if URL =
//    * "...?key=value", getArg("key", null) returns "value".
//    *
//    * @param name
//    * @param def the default value to return if specified parameter in unset
//    * @return the parameter found in the query string or specified default value
//    */
//   String getArg(String name, String def);
// 
//   /**
//    * Returns a field from form data (only valid for POST requests).
//    */
//   String getForm(String field);
// 
//   /**
//    * Returns a list containing all occurrences of a given parameter in query
//    * string, or an empty list if none is found.
//    *
//    * @param name the parameter's name
//    */
//   List<String> getArgs(String name);
// 
//   InputStream getInputStream();
// }
// 
// Path: jflask/src/main/java/net/jflask/SuccessHandler.java
// public interface SuccessHandler {
//   /**
//    * Called when a route handler was successfully called.
//    *
//    * @param r the request
//    * @param method the java method invoked by reflection
//    * @param args the arguments passed to method
//    * @param result the value returned by the handler method
//    */
//   void onSuccess(Request r, Method method, Object[] args, Object result);
// }


import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Test;
import net.jflask.ErrorHandler;
import net.jflask.Request;
import net.jflask.Route;
import net.jflask.SuccessHandler;
package net.jflask.test;




public class HookTest extends AbstractAppTest {

  /** This one conflicts with initial declaration for ErrorHandler. */
  @Route("/")
  public String root() {
    return "root";
  }

  @Route("/barf")
  public String barf() {
    throw new RuntimeException("barf");
  }

  @Route("/hello/:name")
  public String getOk(String name) {
    return "Hello " + name;
  }

  /**
   * Check that 404 and other errors can be handled by ErrorHandlers.
   */
  @Test
  public void testErrorHook() throws Exception {

    final LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>();

// Path: jflask/src/main/java/net/jflask/ErrorHandler.java
// public interface ErrorHandler {
//   /**
//    * Handles an error (either a 404 error due to invalid URL or a 500 error
//    * due to an exception thrown by a handler).
//    *
//    * @param status the request status sent back to client
//    * @param request the request sent by client
//    * @param t optional error (null in case of 404)
//    */
//   void onError(int status, Request request, Throwable t);
// }
// 
// Path: jflask/src/main/java/net/jflask/Request.java
// public interface Request {
// 
//   /**
//    * Returns the part of this request's URL from the protocol name up to the
//    * query string in the first line of the HTTP request.
//    */
//   String getRequestURI();
// 
//   /**
//    * Returns the query string contained in request URL after the path. This
//    * method returns <code>null</code> if the URL does not have a query string.
//    * Same as the value of the CGI variable QUERY_STRING.
//    *
//    * @return a <code>String</code> containing the query string or
//    *         <code>null</code> if the URL contains no query string
//    */
// 
//   String getQueryString();
//   
//   /**
//    * Returns the HTTP verb (GET, POST, etc.) used in the request.
//    */
//   String getMethod();
// 
//   /**
//    * Returns parameter submitted in the query string, eg. if URL =
//    * "...?key=value", getArg("key", null) returns "value".
//    *
//    * @param name
//    * @param def the default value to return if specified parameter in unset
//    * @return the parameter found in the query string or specified default value
//    */
//   String getArg(String name, String def);
// 
//   /**
//    * Returns a field from form data (only valid for POST requests).
//    */
//   String getForm(String field);
// 
//   /**
//    * Returns a list containing all occurrences of a given parameter in query
//    * string, or an empty list if none is found.
//    *
//    * @param name the parameter's name
//    */
//   List<String> getArgs(String name);
// 
//   InputStream getInputStream();
// }
// 
// Path: jflask/src/main/java/net/jflask/SuccessHandler.java
// public interface SuccessHandler {
//   /**
//    * Called when a route handler was successfully called.
//    *
//    * @param r the request
//    * @param method the java method invoked by reflection
//    * @param args the arguments passed to method
//    * @param result the value returned by the handler method
//    */
//   void onSuccess(Request r, Method method, Object[] args, Object result);
// }


// Path: jflask/src/test/java/net/jflask/test/HookTest.java
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.junit.Assert;
import org.junit.Test;
import net.jflask.ErrorHandler;
import net.jflask.Request;
import net.jflask.Route;
import net.jflask.SuccessHandler;

package net.jflask.test;




public class HookTest extends AbstractAppTest {

  /** This one conflicts with initial declaration for ErrorHandler. */
  @Route("/")
  public String root() {
    return "root";
  }

  @Route("/barf")
  public String barf() {
    throw new RuntimeException("barf");
  }

  @Route("/hello/:name")
  public String getOk(String name) {
    return "Hello " + name;
  }

  /**
   * Check that 404 and other errors can be handled by ErrorHandlers.
   */
  @Test
  public void testErrorHook() throws Exception {

    final LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>();

    app.addErrorHandler(new ErrorHandler() {