             self.userStore[user.id] = user
             respondWith(user, nil)
         }
-        
-        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
-        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
-        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]
-        
+
+        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
+        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
+        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]
+
         buildServerTest(router, timeout: 30)
             // Test that handler is invoked successfully when all middlewares are satisfied
             .request("put", path: "/userMultiMiddleware/1", data: user, headers: goodHeaders)
             .hasStatus(.OK)
             .hasContentType(withPrefix: "application/json")
             .hasData(user)
-            
+
             // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
             .request("put", path: "/userMultiMiddleware/1", data: user, headers: missing2ndHeader)
             .hasStatus(.notAcceptable)
             .hasNoData()
-            
+
             // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
             .request("put", path: "/userMultiMiddleware/1", data: user, headers: missing3rdHeader)
             .hasStatus(.badRequest)
             .hasNoData()
-            
-            .run()
-    }
-    
+
+            .run()
+    }
+
     func testSingleMiddlewarePatch() {
         let user = User(id: 1, name: "NewUser")
-        
+
         router.patch("/userMiddleware") { (middleware: UserMiddleware, id: Int, user: User, respondWith: (User?, RequestError?) -> Void) in
             print("PATCH on /userMiddleware for user \(user) - received header \(middleware.header)")
             self.userStore[user.id] = user
             respondWith(user, nil)
         }
-        
+
         buildServerTest(router, timeout: 30)
             .request("patch", path: "/userMiddleware/1", data: user, headers: ["TestHeader": "Hello"])
             .hasStatus(.OK)
             .hasContentType(withPrefix: "application/json")
             .hasData(user)
-            
+
             .request("patch", path: "/userMiddleware/1", data: user)
             .hasStatus(.badRequest)
             .hasNoData()
-            
-            .run()
-    }
-    
+
+            .run()
+    }
+
     func testMultipleMiddlewarePatch() {
         let user = User(id: 1, name: "NewUser")
-        
+
         router.patch("/userMultiMiddleware") { (middleware: UserMiddleware, middleware2: UserMiddleware2, middleware3: UserMiddleware3, id: Int, user: User, respondWith: (User?, RequestError?) -> Void) in
             print("PATCH on /userMultiMiddleware for user \(user) - received headers \(middleware.header), \(middleware2.header), \(middleware3.header)")
             self.userStore[user.id] = user
             respondWith(user, nil)
         }
-        
-        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
-        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
-        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]
-        
+
+        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
+        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
+        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]
+
         buildServerTest(router, timeout: 30)
             // Test that handler is invoked successfully when all middlewares are satisfied
             .request("patch", path: "/userMultiMiddleware/1", data: user, headers: goodHeaders)
             .hasStatus(.OK)
             .hasContentType(withPrefix: "application/json")
             .hasData(user)
-            
+
             // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
             .request("patch", path: "/userMultiMiddleware/1", data: user, headers: missing2ndHeader)
             .hasStatus(.notAcceptable)
             .hasNoData()
-            
+
             // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
             .request("patch", path: "/userMultiMiddleware/1", data: user, headers: missing3rdHeader)
             .hasStatus(.badRequest)
             .hasNoData()
-            
+
             .run()
     }
 }

            print("GET on /userMiddleware - received header \(middleware.header)")
            respondWith(user, nil)
        }
        
        
        buildServerTest(router, timeout: 30)
            .request("get", path: "/userMiddleware", headers: ["TestHeader": "Hello"])
            .hasStatus(.OK)
            .hasContentType(withPrefix: "application/json")
            .hasData(user)
            
            .request("get", path: "/userMiddleware")
            .hasStatus(.badRequest)
            .hasNoData()
            
            .run()
    }
    
    func testMultipleMiddlewareGetSingleton() {
        let user = User(id: 5, name: "Neil")
        
        router.get("/userMultiMiddleware") { (middleware: UserMiddleware, middleware2: UserMiddleware2, middleware3: UserMiddleware3, respondWith: (User?, RequestError?) -> Void) in
            print("GET on /userMultiMiddleware - received headers \(middleware.header), \(middleware2.header), \(middleware3.header)")
            respondWith(user, nil)
        }
        
        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]
        
        buildServerTest(router, timeout: 30)
            // Test that handler is invoked successfully when all middlewares are satisfied
            .request("get", path: "/userMultiMiddleware", headers: goodHeaders)
            .hasStatus(.OK)
            .hasContentType(withPrefix: "application/json")
            .hasData(user)
            
            // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
            .request("get", path: "/userMultiMiddleware", headers: missing2ndHeader)
            .hasStatus(.notAcceptable)
            .hasNoData()
            
            // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
            .request("get", path: "/userMultiMiddleware", headers: missing3rdHeader)
            .hasStatus(.badRequest)
            .hasNoData()
            
            .run()
    }
    
    func testSingleMiddlewareGetArray() {
        let userArray = [User(id: 1, name: "Andy"), User(id: 2, name: "Dave")]
        
        router.get("/userMiddleware") { (middleware: UserMiddleware, respondWith: ([User]?, RequestError?) -> Void) in
            print("GET on /userMiddleware - received header \(middleware.header)")
            respondWith(userArray, nil)
        }
        
        
        buildServerTest(router, timeout: 30)
            .request("get", path: "/userMiddleware", headers: ["TestHeader": "Hello"])
            .hasStatus(.OK)
            .hasContentType(withPrefix: "application/json")
            .hasData(userArray)
            
            .request("get", path: "/userMiddleware")
            .hasStatus(.badRequest)
            .hasNoData()
            
            .run()
    }
    
    func testMultipleMiddlewareGetArray() {
        let userArray = [User(id: 1, name: "Andy"), User(id: 2, name: "Dave")]


        }

        let user = User(id: 4, name: "Matt")

        buildServerTest(router, timeout: 30)
            .request("post", path: "/userMiddleware", data: user, headers: ["TestHeader": "Hello"])
            .hasStatus(.created)
            .hasContentType(withPrefix: "application/json")
            .hasData(user)

            .request("post", path: "/userMiddleware", data: user)
            .hasStatus(.badRequest)
            .hasNoData()

            .run()
    }

    func testMultipleMiddlewarePost() {
        router.post("/userMultiMiddleware") { (middleware: UserMiddleware, middleware2: UserMiddleware2, middleware3: UserMiddleware3, user: User, respondWith: (User?, RequestError?) -> Void) in
            print("POST on /userMultiMiddleware for user \(user) - received headers \(middleware.header), \(middleware2.header), \(middleware3.header)")
            self.userStore[user.id] = user
            respondWith(user, nil)
        }

        let user = User(id: 5, name: "Neil")
        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]

        buildServerTest(router, timeout: 30)
            // Test that handler is invoked successfully when all middlewares are satisfied
            .request("post", path: "/userMultiMiddleware", data: user, headers: goodHeaders)
            .hasStatus(.created)
            .hasContentType(withPrefix: "application/json")
            .hasData(user)

            // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
            .request("post", path: "/userMultiMiddleware", data: user, headers: missing2ndHeader)
            .hasStatus(.notAcceptable)
            .hasNoData()

            // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
            .request("post", path: "/userMultiMiddleware", data: user, headers: missing3rdHeader)
            .hasStatus(.badRequest)
            .hasNoData()

            .run()
    }

    func testSingleMiddlewarePostIdentifier() {
        // Expected user: User(id: 1, name: "Andy")
        guard let user = userStore[1] else {
            XCTFail("no value found for userStore[1]")
            return
        }

        router.post("/userMiddleware") { (middleware: UserMiddleware, user: User, respondWith: (Int?, User?, RequestError?) -> Void) in
            print("POST with identifier on /userMiddleware for user \(user) - received header \(middleware.header)")
            let id = 1
            self.userStore[id] = user
            respondWith(id, user, nil)
        }

        buildServerTest(router, timeout: 30)
            .request("post", path: "/userMiddleware", data: user, headers: ["TestHeader": "Hello"])
            .hasStatus(.created)
            .hasContentType(withPrefix: "application/json")
            .hasData(user)

            .request("post", path: "/userMiddleware", data: user)
            .hasStatus(.badRequest)
            .hasNoData()

            .run()
    }

    func testMultipleMiddlewarePostIdentifier() {
        // Expected user: User(id: 1, name: "Andy")
        guard let user = userStore[1] else {
            XCTFail("no value found for userStore[1]")
            return
        }

        router.post("/userMultiMiddleware") { (middleware: UserMiddleware, middleware2: UserMiddleware2, middleware3: UserMiddleware3, user: User, respondWith: (Int?, User?, RequestError?) -> Void) in
            print("POST on /userMultiMiddleware for user \(user) - received headers \(middleware.header), \(middleware2.header), \(middleware3.header)")
            let id = 1
            self.userStore[id] = user
            respondWith(id, user, nil)
        }

        let goodHeaders = ["TestHeader": "Foo", "TestHeader2": "Bar", "TestHeader3": "Baz"]
        let missing2ndHeader = ["TestHeader": "Foo", "TestHeader3": "Baz"]
        let missing3rdHeader = ["TestHeader": "Foo", "TestHeader2": "Bar"]

        buildServerTest(router, timeout: 30)
            // Test that handler is invoked successfully when all middlewares are satisfied
            .request("post", path: "/userMultiMiddleware", data: user, headers: goodHeaders)
            .hasStatus(.created)
            .hasContentType(withPrefix: "application/json")
            .hasData(user)

            // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
            .request("post", path: "/userMultiMiddleware", data: user, headers: missing2ndHeader)
            .hasStatus(.notAcceptable)
            .hasNoData()

            // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
            .request("post", path: "/userMultiMiddleware", data: user, headers: missing3rdHeader)
            .hasStatus(.badRequest)
            .hasNoData()

            .run()
    }

    func testSingleMiddlewarePut() {
        let user = User(id: 1, name: "NewUser")

