Search in sources :

Example 1 with MarkdownConversionException

use of uk.nhs.digital.common.components.apispecification.commonmark.MarkdownConversionException in project hippo by NHS-digital-website.

the class CommonmarkMarkdownConverterTest method throwsException_onNegativeTopHeadingLevel.

@Test
public void throwsException_onNegativeTopHeadingLevel() {
    // given
    final String irrelevantMarkdown = randomString();
    final String irrelevantHeadingIdPrefix = randomString();
    final int illegalTopLevelHeading = -RandomUtils.nextInt();
    // when
    final ThrowingRunnable action = () -> commonmarkMarkdownConverter.toHtml(irrelevantMarkdown, irrelevantHeadingIdPrefix, illegalTopLevelHeading);
    // then
    final MarkdownConversionException actualException = assertThrows(MarkdownConversionException.class, action);
    assertThat("Exception message provides failure's details.", actualException.getMessage(), is("Failed to convert Markdown " + irrelevantMarkdown));
    assertThat("Cause highlights argument validation error.", actualException.getCause().getMessage(), is("Argument topHeadingLevel has to be greater than or equal to zero but was " + illegalTopLevelHeading));
}
Also used : MarkdownConversionException(uk.nhs.digital.common.components.apispecification.commonmark.MarkdownConversionException) RandomTestUtils.randomString(uk.nhs.digital.test.util.RandomTestUtils.randomString) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 ThrowingRunnable (org.junit.function.ThrowingRunnable)1 MarkdownConversionException (uk.nhs.digital.common.components.apispecification.commonmark.MarkdownConversionException)1 RandomTestUtils.randomString (uk.nhs.digital.test.util.RandomTestUtils.randomString)1