Skip to content

Commit

Permalink
Code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
fugerit79 committed Apr 5, 2024
1 parent 5c8eb03 commit 71e410d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static List<ServiceMessage> filterBySeverity( List<ServiceMessage> messag
return messages.stream().filter( m -> m.getSeverity().equalsIgnoreCase( severity ) ).collect( Collectors.toList() );
}

public static ServiceMessage newMessageByStatus(Response.Status status, String message ) {
public static ServiceMessage newMessageByStatus(Response.StatusType status, String message ) {
switch ( status.getFamily() ) {
case INFORMATIONAL:
return newDefaultInfoMessage( message );
Expand Down Expand Up @@ -66,7 +66,7 @@ public static ServiceMessage newDefaultSuccessMessage( String message ) {
}

public static ServiceMessage newDefaultInfoMessage( String message ) {
return newSuccessMessage( ServiceMessage.SEVERITY_INFO, message );
return newInfoMessage( ServiceMessage.SEVERITY_INFO, message );
}

public static ServiceMessage newErrorMessage( String code, String message ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package test.org.fugerit.java.emp.sm.service;

import jakarta.ws.rs.core.Response;
import org.fugerit.java.emp.sm.service.ServiceMessage;

import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -28,10 +29,11 @@ void testMessageAllArgs() {

@Test
void testNewMessage() {
Assertions.assertEquals( TEST_MESSAGE, ServiceResponseHelper.newDefaultErrorMessage( TEST_MESSAGE ).getText() );
Assertions.assertEquals( TEST_MESSAGE, ServiceResponseHelper.newDefaultWarningMessage( TEST_MESSAGE ).getText() );
Assertions.assertEquals( TEST_MESSAGE, ServiceResponseHelper.newDefaultSuccessMessage( TEST_MESSAGE ).getText() );
Assertions.assertEquals( TEST_MESSAGE, ServiceResponseHelper.newDefaultInfoMessage( TEST_MESSAGE ).getText() );
Assertions.assertEquals( TEST_MESSAGE, ServiceResponseHelper.newMessageByStatus( Response.Status.OK, TEST_MESSAGE ).getText() );
Assertions.assertEquals( TEST_MESSAGE, ServiceResponseHelper.newMessageByStatus( Response.Status.INTERNAL_SERVER_ERROR, TEST_MESSAGE ).getText() );
Assertions.assertEquals( TEST_MESSAGE, ServiceResponseHelper.newMessageByStatus( Response.Status.BAD_REQUEST, TEST_MESSAGE ).getText() );
Assertions.assertEquals( TEST_MESSAGE, ServiceResponseHelper.newMessageByStatus( new TestStatus( 100, "Test Info" ), TEST_MESSAGE ).getText() );
Assertions.assertEquals( TEST_MESSAGE, ServiceResponseHelper.newMessageByStatus( new TestStatus( 800, "Test Warning" ), TEST_MESSAGE ).getText() );
}

@Test
Expand All @@ -46,3 +48,35 @@ void testMessageNoArgs() {
}

}

class TestStatus implements Response.StatusType {

private int statusCode;

private String reasonPhrase;

public TestStatus(int statusCode, String reasonPhrase) {
this.statusCode = statusCode;
this.reasonPhrase = reasonPhrase;
}

@Override
public Response.Status toEnum() {
return Response.StatusType.super.toEnum();
}

@Override
public int getStatusCode() {
return this.statusCode;
}

@Override
public Response.Status.Family getFamily() {
return Response.Status.Family.familyOf( this.getStatusCode() );
}

@Override
public String getReasonPhrase() {
return this.reasonPhrase;
}
}

0 comments on commit 71e410d

Please sign in to comment.