@Test public void testCleanInput() { assertEquals("test1\ntest2", AsciidoctorRenderer.cleanJavadocInput(" test1\n test2\n")); assertEquals("@", AsciidoctorRenderer.cleanJavadocInput("{@literal @}")); assertEquals("/*\ntest\n*/", AsciidoctorRenderer.cleanJavadocInput("/*\ntest\n*\\/")); assertEquals("@", AsciidoctorRenderer.cleanJavadocInput("{at}")); assertEquals("/", AsciidoctorRenderer.cleanJavadocInput("{slash}")); }
@Test public void testTagRender() { Doc mockDoc = mock(Doc.class); Tag mockTag = mock(Tag.class); String tagName = "tagName"; String tagText = "tagText"; String asciidoctorRenderedString = "rendered"; when(mockTag.name()).thenReturn(tagName); when(mockTag.text()).thenReturn(tagText); when(mockDoc.getRawCommentText()).thenReturn("input"); when(mockDoc.commentText()).thenReturn("input"); when(mockDoc.tags()).thenReturn(new Tag[] {mockTag}); when(mockAsciidoctor.render(eq("input"), argThat(new OptionsMatcher(false)))) .thenReturn("input"); when(mockAsciidoctor.render(eq(tagText), argThat(new OptionsMatcher(true)))) .thenReturn(asciidoctorRenderedString); renderer.renderDoc(mockDoc); verify(mockAsciidoctor).render(eq("input"), argThat(new OptionsMatcher(false))); verify(mockAsciidoctor).render(eq(tagText), argThat(new OptionsMatcher(true))); verify(mockDoc).setRawCommentText("input"); verify(mockDoc).setRawCommentText("input\n" + tagName + " " + asciidoctorRenderedString + "\n"); }
@Test public void testAtLiteralRender() { Doc mockDoc = mock(Doc.class); String convertedText = "Test"; String rawText = "@" + convertedText; when(mockDoc.getRawCommentText()).thenReturn(rawText); when(mockDoc.commentText()).thenReturn("input"); when(mockDoc.tags()).thenReturn(new Tag[] {}); when(mockAsciidoctor.render(anyString(), any(Options.class))).thenReturn("input"); renderer.renderDoc(mockDoc); verify(mockDoc).setRawCommentText("{@literal @}" + convertedText); verify(mockAsciidoctor).render(anyString(), any(Options.class)); }
@Test public void testParamTagWithTypeParameter() { String commentText = "comment"; String param1Name = "T"; String param1Desc = ""; String param1Text = "<" + param1Name + ">"; String param2Name = "X"; String param2Desc = "description"; String param2Text = "<" + param2Name + "> " + param2Desc; String sourceText = commentText + "\n@param " + param1Text + "\n@param " + param2Text; Doc mockDoc = mock(Doc.class); when(mockDoc.getRawCommentText()).thenReturn(sourceText); when(mockDoc.commentText()).thenReturn(commentText); Tag[] tags = new Tag[2]; ParamTag mockTag1 = mock(ParamTag.class); when(mockTag1.name()).thenReturn("@param"); when(mockTag1.isTypeParameter()).thenReturn(true); when(mockTag1.parameterName()).thenReturn(param1Name); when(mockTag1.parameterComment()).thenReturn(param1Desc); tags[0] = mockTag1; ParamTag mockTag2 = mock(ParamTag.class); when(mockTag2.name()).thenReturn("@param"); when(mockTag2.isTypeParameter()).thenReturn(true); when(mockTag2.parameterName()).thenReturn(param2Name); when(mockTag2.parameterComment()).thenReturn(param2Desc); tags[1] = mockTag2; when(mockDoc.tags()).thenReturn(tags); when(mockAsciidoctor.render(eq(commentText), any(Options.class))).thenReturn(commentText); when(mockAsciidoctor.render(eq(param2Desc), any(Options.class))).thenReturn(param2Desc); renderer.renderDoc(mockDoc); verify(mockAsciidoctor).render(eq(commentText), argThat(new OptionsMatcher(false))); verify(mockAsciidoctor).render(eq(param2Desc), argThat(new OptionsMatcher(true))); // fixture step verify(mockDoc).setRawCommentText(eq(sourceText)); // result step verify(mockDoc).setRawCommentText(eq(sourceText)); }