CoapRequestBuilder { static Request build(String method) { Request request = null; switch (method) { case GET_METHOD: request = Request.newGet(); break; case POST_METHOD: request = Request.newPost(); break; case PUT_METHOD: request = Request.newPut(); break; case DELETE_METHOD: request = Request.newDelete(); break; case DISCOVER_METHOD: request = Request.newGet(); break; case OBSERVE_METHOD: request = Request.newGet(); request.setObserve(); break; } return request; }    }
@Test void build_GetRequest() { Request request = CoapRequestBuilder.build(CoapRequestBuilder.GET_METHOD); assertEquals(CoAP.Code.GET, request.getCode()); }
@Test void build_PostRequest() { Request request = CoapRequestBuilder.build(CoapRequestBuilder.POST_METHOD); assertEquals(CoAP.Code.POST, request.getCode()); }
@Test void build_PutRequest() { Request request = CoapRequestBuilder.build(CoapRequestBuilder.PUT_METHOD); assertEquals(CoAP.Code.PUT, request.getCode()); }
@Test void build_DeleteRequest() { Request request = CoapRequestBuilder.build(CoapRequestBuilder.DELETE_METHOD); assertEquals(CoAP.Code.DELETE, request.getCode()); }
@Test void build_ObserveRequest() { Request request = CoapRequestBuilder.build(CoapRequestBuilder.OBSERVE_METHOD); assertEquals(CoAP.Code.GET, request.getCode()); assertTrue(request.isObserve()); }
@Test void build_DiscoverRequest() { Request request = CoapRequestBuilder.build(CoapRequestBuilder.DISCOVER_METHOD); assertEquals(CoAP.Code.GET, request.getCode()); }