Created
July 10, 2023 20:28
-
-
Save AdamJHowell/d3611a80f25477adf5f1ceb14e88854b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.fasterxml.jackson.core.JsonProcessingException; | |
import com.fasterxml.jackson.databind.JsonNode; | |
import com.fasterxml.jackson.databind.ObjectMapper; | |
import org.junit.Test; | |
import static org.junit.Assert.*; | |
public class RequestIdHandlerTest | |
{ | |
@Test | |
public void getRequestIdInt() throws JsonProcessingException | |
{ | |
int value = 5; | |
RequestIdHandler requestIdHandler = new RequestIdHandler( value ); | |
assertEquals( value, requestIdHandler.getRequestIdAsInt() ); | |
} | |
@Test | |
public void setRequestIdJsonNode() throws JsonProcessingException | |
{ | |
String value = "\"Five\""; | |
String theAnswerToLifeTheUniverseAndEverything = "\"Forty two\""; | |
ObjectMapper objectMapper = new ObjectMapper(); | |
JsonNode stringNode1 = objectMapper.readTree( value ); | |
JsonNode stringNode2 = objectMapper.readTree( theAnswerToLifeTheUniverseAndEverything ); | |
RequestIdHandler requestIdHandler = new RequestIdHandler( "\"" + stringNode1.asText() + "\"" ); | |
assertEquals( stringNode1.asText(), requestIdHandler.getRequestIdAsString() ); | |
requestIdHandler.setRequestId( stringNode2 ); | |
assertEquals( stringNode2.asText(), requestIdHandler.getRequestIdAsString() ); | |
} | |
@Test | |
public void setRequestIdString() throws JsonProcessingException | |
{ | |
String firstValue = "\"Five\""; | |
String theAnswerToLifeTheUniverseAndEverything = "\"Forty two\""; | |
RequestIdHandler requestIdHandler = new RequestIdHandler( firstValue ); | |
assertEquals( firstValue, "\"" + requestIdHandler.getRequestIdAsString() + "\"" ); | |
requestIdHandler.setRequestId( theAnswerToLifeTheUniverseAndEverything ); | |
assertEquals( theAnswerToLifeTheUniverseAndEverything, "\"" + requestIdHandler.getRequestIdAsString() + "\"" ); | |
} | |
@Test | |
public void setRequestIdInt() throws JsonProcessingException | |
{ | |
int value = 5; | |
int theAnswerToLifeTheUniverseAndEverything = 42; | |
RequestIdHandler requestIdHandler = new RequestIdHandler( value ); | |
assertEquals( value, requestIdHandler.getRequestIdAsInt() ); | |
requestIdHandler.setRequestId( theAnswerToLifeTheUniverseAndEverything ); | |
assertEquals( theAnswerToLifeTheUniverseAndEverything, requestIdHandler.getRequestIdAsInt() ); | |
} | |
@Test | |
public void isRequestIdAutoIncrement() throws JsonProcessingException | |
{ | |
int value = 5; | |
RequestIdHandler requestIdHandler = new RequestIdHandler( value ); | |
assertTrue( requestIdHandler.isRequestIdAutoIncrement() ); | |
requestIdHandler.incrementRequestId(); | |
assertEquals( value + 1, requestIdHandler.getRequestIdAsInt() ); | |
String firstValue = "\"Five\""; | |
requestIdHandler = new RequestIdHandler( firstValue ); | |
assertFalse( requestIdHandler.isRequestIdAutoIncrement() ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment