Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for the jsonBeautifier #1221

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void accessBindings() throws Exception {
}

@Test
public void xmlFromFileTest() throws Exception {
void xmlFromFileTest() throws Exception {
setAndHandleRequest("./project_template.xml");
assertEquals("minister", evaluateXPathAndReturnFirstNode(createXPathExpression("/project/part[2]/title")).trim());
}
Expand All @@ -172,7 +172,7 @@ private String evaluateXPathAndReturnFirstNode(XPathExpression xpath) throws XPa
}

@Test
public void nonXmlTemplateListTest() throws Exception {
void nonXmlTemplateListTest() throws Exception {
setAndHandleRequest("./template_test.json");

assertEquals("food1",
Expand All @@ -184,7 +184,7 @@ public void nonXmlTemplateListTest() throws Exception {
}

@Test
public void initTest() {
void initTest() {
assertThrows(IllegalStateException.class, () -> {
ti.setLocation("./template_test.json");
ti.setTextTemplate("${minister}");
Expand All @@ -193,15 +193,15 @@ public void initTest() {
}

@Test
public void notFoundTemplateException() {
void notFoundTemplateException() {
assertThrows(ResourceRetrievalException.class, () -> {
ti.setLocation("./not_existent_file");
ti.init(router);
});
}

@Test
public void innerTagTest() throws Exception {
void innerTagTest() throws Exception {
ti.setTextTemplate("${title}");
ti.init(router);
ti.handleRequest(exc);
Expand All @@ -228,6 +228,24 @@ void contentTypeTestNoXml() throws Exception {
assertEquals("text/plain",exc.getRequest().getHeader().getContentType());
}

@Test
void testPrettify() {
String inputJson = "\t{\n\n\t\t\"name\":\"John\"\t\t,\"age\":30}";
String expectedPrettyJson = """
{
"name" : "John",
"age" : 30
}""";
String result = ti.prettifyJson(inputJson);
assertEquals(expectedPrettyJson, result);
}

@Test
void testPrettifyWithInvalidJson() {
String invalidJson = "{name:\"John\",age:30}";
assertEquals(invalidJson, ti.prettifyJson(invalidJson));
}

private void setAndHandleRequest(String location) throws Exception {
ti.setLocation(location);
ti.init(router);
Expand Down
Loading