diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptorTest.java index 0956d22e78..0379659ce6 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptorTest.java @@ -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()); } @@ -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", @@ -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}"); @@ -193,7 +193,7 @@ public void initTest() { } @Test - public void notFoundTemplateException() { + void notFoundTemplateException() { assertThrows(ResourceRetrievalException.class, () -> { ti.setLocation("./not_existent_file"); ti.init(router); @@ -201,7 +201,7 @@ public void notFoundTemplateException() { } @Test - public void innerTagTest() throws Exception { + void innerTagTest() throws Exception { ti.setTextTemplate("${title}"); ti.init(router); ti.handleRequest(exc); @@ -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);