Skip to content

Commit

Permalink
Remove AssertJ in favor of plain JUnit5
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderGirgis committed Apr 1, 2020
1 parent 3cb1048 commit b138325
Showing 1 changed file with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

class MarkdownFormatterTest {

Expand All @@ -17,44 +19,48 @@ void setUp() {

@Test
void formatWhenFormattingPlainTextThenReturnsTextWrappedInParagraph() {
assertThat(markdownFormatter.format("Hello World")).isEqualTo("<p>Hello World</p>");
assertEquals("<p>Hello World</p>", markdownFormatter.format("Hello World"));
}

@Test
void formatWhenFormattingComplexMarkupThenReturnsOnlyOneLine() {
String source = "Markup\n\n* list item one\n* list item 2\n\n rest";
assertThat(markdownFormatter.format(source))
.contains("Markup<br />")
.contains("<li>list item one</li>")
.contains("<li>list item 2</li>")
.contains("> rest")
.doesNotContain("\n");

String actual = markdownFormatter.format(source);

// Only test relevant bits and ignore possible whitespace introduced by html-renderer
assertTrue(actual.contains("Markup<br />"));
assertTrue(actual.contains("<li>list item one</li>"));
assertTrue(actual.contains("<li>list item 2</li>"));
assertTrue(actual.contains("> rest"));
assertFalse(actual.contains("\n"));
}

@Test
void formatWhenFormattingEmptyStringThenReturnsEmptyString() {
assertThat(markdownFormatter.format("")).isEqualTo("");
assertEquals("", markdownFormatter.format(""));
}

@Test
void formatWhenFormattingNullThenThrowsException() {
assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> markdownFormatter.format(null))
.withMessageContaining("Field Text should not be null, when handed to formatter")
.withNoCause();
Exception exception = assertThrows(NullPointerException.class, () -> markdownFormatter.format(null));
assertEquals("Field Text should not be null, when handed to formatter", exception.getMessage());
}

@Test
void formatWhenMarkupContainingStrikethroughThenContainsMatchingDel() {
assertThat(markdownFormatter.format("a ~~b~~ b")).contains("<del>b</del>");
// Only test strikethrough extension
assertTrue(markdownFormatter.format("a ~~b~~ b").contains("<del>b</del>"));
}

@Test
void formatWhenMarkupContainingTaskListThenContainsFormattedTaskList() {
assertThat(markdownFormatter.format("Some text\n" +
String actual = markdownFormatter.format("Some text\n" +
"* [ ] open task\n" +
"* [x] closed task\n\n" +
"some other text"))
.contains("<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" disabled=\"disabled\" readonly=\"readonly\" />&nbsp;open task</li>")
.contains("<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" readonly=\"readonly\" />&nbsp;closed task</li>");
"some other text");
// Only test list items
assertTrue(actual.contains("<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" disabled=\"disabled\" readonly=\"readonly\" />&nbsp;open task</li>"));
assertTrue(actual.contains("<li class=\"task-list-item\"><input type=\"checkbox\" class=\"task-list-item-checkbox\" checked=\"checked\" disabled=\"disabled\" readonly=\"readonly\" />&nbsp;closed task</li>"));
}
}

0 comments on commit b138325

Please sign in to comment.