/** * Gets the string representation of a CoAP code. * * @param code the CoAP code. * @return a string following the pattern C.DD where C is the code class nd DD is the code detail. */ public static String formatCode(final int code) { return formatCode(getCodeClass(code), getCodeDetail(code)); }
@Test public void testFormatCode() { // Requests assertThat(CoAP.formatCode(Code.GET.value), is("0.01")); assertThat(CoAP.formatCode(Code.POST.value), is("0.02")); // success assertThat(CoAP.formatCode(ResponseCode.CREATED.value), is("2.01")); assertThat(CoAP.formatCode(ResponseCode.CHANGED.value), is("2.04")); assertThat(CoAP.formatCode(ResponseCode.CONTENT.value), is("2.05")); // errors assertThat(CoAP.formatCode(ResponseCode.BAD_REQUEST.value), is("4.00")); assertThat(CoAP.formatCode(ResponseCode.REQUEST_ENTITY_INCOMPLETE.value), is("4.08")); assertThat(CoAP.formatCode(ResponseCode.REQUEST_ENTITY_TOO_LARGE.value), is("4.13")); assertThat(CoAP.formatCode(ResponseCode.UNSUPPORTED_CONTENT_FORMAT.value), is("4.15")); // server errors assertThat(CoAP.formatCode(ResponseCode.INTERNAL_SERVER_ERROR.value), is("5.00")); assertThat(CoAP.formatCode(ResponseCode.NOT_IMPLEMENTED.value), is("5.01")); assertThat(CoAP.formatCode(ResponseCode.SERVICE_UNAVAILABLE.value), is("5.03")); }