Skip to content

Commit

Permalink
Make ContentFormat and ResponseCode toString() prettier.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jun 25, 2021
1 parent baa10b4 commit afc22f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public class ResponseCodeUtilTest {

@Test
public void known_coap_code_to_known_lwm2m_Code() {
org.eclipse.leshan.core.ResponseCode lwM2mResponseCode = ResponseCodeUtil.toLwM2mResponseCode(ResponseCode.CREATED);
org.eclipse.leshan.core.ResponseCode lwM2mResponseCode = ResponseCodeUtil
.toLwM2mResponseCode(ResponseCode.CREATED);

Assert.assertEquals(org.eclipse.leshan.core.ResponseCode.CREATED, lwM2mResponseCode);
Assert.assertEquals("CREATED", lwM2mResponseCode.toString());
Assert.assertEquals("CREATED(201)", lwM2mResponseCode.toString());
}

@Test
Expand All @@ -49,7 +50,8 @@ public void known_lwm2m_code_to_known_coap_code() {

@Test
public void unknown_lwm2m_code_to_known_coap_code() {
ResponseCode coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(503));
ResponseCode coapResponseCode = ResponseCodeUtil
.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(503));

Assert.assertEquals(ResponseCode.SERVICE_UNAVAILABLE, coapResponseCode);
}
Expand All @@ -69,7 +71,8 @@ public void unknown_lwm2m_code_to_unknown_coap_code() {
// californium behavior is not really consistent

// for success : code value is lost but we know we use an unknown code
ResponseCode coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(206));
ResponseCode coapResponseCode = ResponseCodeUtil
.toCoapResponseCode(new org.eclipse.leshan.core.ResponseCode(206));
Assert.assertEquals(ResponseCode._UNKNOWN_SUCCESS_CODE, coapResponseCode);

// for client error,: unknown code is replace by BAD REQUEST ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,7 @@ public static ResponseCode fromCode(int code) {

@Override
public String toString() {
if (UNKNOWN.equals(name))
return String.format("%s(%d)", name, code);
else
return name;
return String.format("%s(%d)", name, code);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static ContentFormat fromName(String name) {

@Override
public String toString() {
return String.format("ContentFormat [name=%s, code=%s]", name, code);
return String.format("%s(%s)", name, code);
}

@Override
Expand Down

0 comments on commit afc22f3

Please sign in to comment.