             .hasNoData()
             .has { _ in XCTAssertNil(self.userStore[1]) }
 
-            
             // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
             .request("delete", path: "/userMultiMiddleware/1", headers: missing2ndHeader)
             .hasStatus(.notAcceptable)
             .hasNoData()
-            
+
             // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
             .request("delete", path: "/userMultiMiddleware/1", headers: missing3rdHeader)
             .hasStatus(.badRequest)
             .hasNoData()
-            
-            .run()
-    }
-    
+
+            .run()
+    }
+
     func testSingleMiddlewareDeleteParameters() {
-        
+
         router.delete("/userMiddleware") { (middleware: UserMiddleware, query: MyQuery, respondWith: (RequestError?) -> Void) in
             print("DELETE on /userMiddleware - received header \(middleware.header)")
-            guard let _ = self.userStore.removeValue(forKey: query.id) else {
+            guard self.userStore.removeValue(forKey: query.id) != nil else {
                 respondWith(.notFound)
                 return
             }
             respondWith(nil)
         }
-        
-        
+
         buildServerTest(router, timeout: 30)
             .request("delete", path: "/userMiddleware?id=1", headers: ["TestHeader": "Hello"])
             .hasStatus(.noContent)
             .hasNoData()
             .has { _ in XCTAssertNil(self.userStore[1]) }
-            
+
             .request("delete", path: "/userMiddleware?id=1")
             .hasStatus(.badRequest)
             .hasNoData()
-            
-            .run()
-    }
-    
+
+            .run()
+    }
+
     func testMultipleMiddlewareDeleteParameters() {
-        
-        router.delete("/userMultiMiddleware") { (middleware: UserMiddleware, middleware2: UserMiddleware2, middleware3: UserMiddleware3, query: MyQuery,  respondWith: (RequestError?) -> Void) in
+
+        router.delete("/userMultiMiddleware") { (middleware: UserMiddleware, middleware2: UserMiddleware2, middleware3: UserMiddleware3, query: MyQuery, respondWith: (RequestError?) -> Void) in
             print("DELETE on /userMultiMiddleware - received headers \(middleware.header), \(middleware2.header), \(middleware3.header)")
-            guard let _ = self.userStore.removeValue(forKey: query.id) else {
+            guard self.userStore.removeValue(forKey: query.id) != nil else {
                 respondWith(.notFound)
                 return
             }
             respondWith(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("delete", path: "/userMultiMiddleware?id=1", headers: goodHeaders)
             .hasStatus(.noContent)
             .hasNoData()
             .has { _ in XCTAssertNil(self.userStore[1]) }
-            
-            
+
             // Test that Middleware2 fails when its header is missing, by examining the status (.notAcceptable)
             .request("delete", path: "/userMultiMiddleware?id=1", headers: missing2ndHeader)
             .hasStatus(.notAcceptable)
             .hasNoData()
-            
+
             // Test that Middleware3 fails when its header is missing, by examining the status (.badRequest)
             .request("delete", path: "/userMultiMiddleware?id=1", headers: missing3rdHeader)
             .hasStatus(.badRequest)
             .hasNoData()
-            
-            .run()
-    }
-    
+
+            .run()
+    }
+
     func testSingleMiddlewarePost() {
         router.post("/userMiddleware") { (middleware: UserMiddleware, user: User, respondWith: (User?, RequestError?) -> Void) in
             print("POST on /userMiddleware for user \(user) - received header \(middleware.header)")

            self.name = name
        }

        static func ==(lhs: User, rhs: User) -> Bool {
            return lhs.id == rhs.id && lhs.name == rhs.name
        }
    }
    
    struct MyQuery: QueryParams {
        let id: Int
        
        init(id: Int) {
            self.id = id
        }
        
        static func ==(lhs: MyQuery, rhs: MyQuery) -> Bool {
            return lhs.id == rhs.id
        }
    }
    
    // A user-defined structure that can be used in a TypeSafeMiddleware context
    struct UserMiddleware: TestMiddleware {
        let header: String

            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")]

