|
| 1 | +package com.codeborne.pdftest.assertj; |
| 2 | + |
| 3 | +import com.codeborne.pdftest.PDF; |
| 4 | +import org.junit.Test; |
| 5 | + |
| 6 | +import java.io.IOException; |
| 7 | + |
| 8 | +import static com.codeborne.pdftest.assertj.Assertions.assertThat; |
| 9 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 10 | + |
| 11 | +public class ContainsTextTest { |
| 12 | + @Test |
| 13 | + public void canAssertThatPdfContainsText() throws IOException { |
| 14 | + PDF pdf = new PDF(getClass().getClassLoader().getResource("50quickideas.pdf")); |
| 15 | + assertThat(pdf).containsText("50 Quick Ideas to Improve your User Stories"); |
| 16 | + assertThat(pdf).containsText("Gojko Adzic"); |
| 17 | + assertThat(pdf).containsText("©2013 - 2014 Gojko Adzic"); |
| 18 | + assertThat(pdf).containsText("#50quickideas"); |
| 19 | + assertThat(pdf).containsText("https://twitter.com/search?q=#50quickideas"); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void shouldBeCaseSensitive() throws IOException { |
| 24 | + PDF pdf = new PDF(getClass().getClassLoader().getResource("50quickideas.pdf")); |
| 25 | + assertThat(pdf).doesNotContainText("50 quick ideas"); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void shouldIgnoreWhitespaces() throws IOException { |
| 30 | + PDF pdf = new PDF(getClass().getClassLoader().getResource("50quickideas.pdf")); |
| 31 | + assertThat(pdf).containsText("Gojko Adzic"); |
| 32 | + assertThat(pdf).containsText("\tGojko \t Adzic\t"); |
| 33 | + assertThat(pdf).containsText("Gojko \n Adzic\t\n"); |
| 34 | + assertThat(pdf).containsText("Gojko \n Adzic\n"); |
| 35 | + assertThat(pdf).containsText("Gojko\r\n Adzic\r\n"); |
| 36 | + assertThat(pdf).containsText("Gojko \u00a0 Adzic\r\n"); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void errorDescription() throws IOException { |
| 41 | + PDF pdf = new PDF(getClass().getClassLoader().getResource("minimal.pdf")); |
| 42 | + assertThatThrownBy(() -> { |
| 43 | + assertThat(pdf).containsText("Goodbye word"); |
| 44 | + }) |
| 45 | + .isInstanceOf(AssertionError.class) |
| 46 | + .hasMessage("\nExpected: a PDF containing \"Goodbye word\"\n but: was \"Hello World\""); |
| 47 | + } |
| 48 | +} |
0 commit comments