Skip to content

Commit 8a2e7f9

Browse files
authored
Remove hamcrest dependency (#1322)
1 parent 0e2aa39 commit 8a2e7f9

File tree

5 files changed

+25
-42
lines changed

5 files changed

+25
-42
lines changed

openpdf/pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@
6060
<version>5.10.0</version>
6161
<scope>test</scope>
6262
</dependency>
63-
<dependency>
64-
<groupId>org.hamcrest</groupId>
65-
<artifactId>hamcrest</artifactId>
66-
<scope>test</scope>
67-
</dependency>
6863
<dependency>
6964
<groupId>commons-io</groupId>
7065
<artifactId>commons-io</artifactId>

openpdf/src/test/java/com/lowagie/text/factories/RomanNumberFactoryTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.lowagie.text.factories;
22

33
import static com.lowagie.text.factories.RomanNumberFactory.getString;
4-
import static org.hamcrest.MatcherAssert.assertThat;
5-
import static org.hamcrest.Matchers.is;
64
import static org.junit.jupiter.api.Assertions.assertAll;
75
import static org.junit.jupiter.api.Assertions.assertEquals;
86
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -63,7 +61,7 @@ void shouldGetRomanNumeralRepresentation() {
6361
@MethodSource("numeralTestProvider")
6462
void shouldConvertRomanNumeralRepresentation(int input, String expected) {
6563
assertAll(
66-
() -> assertThat(getString(input), is(expected)),
67-
() -> assertThat(getString(input, false), is(expected.toUpperCase())));
64+
() -> assertEquals(expected, getString(input)),
65+
() -> assertEquals(expected.toUpperCase(), getString(input, false)));
6866
}
6967
}

openpdf/src/test/java/com/lowagie/text/pdf/PdfDocumentTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.lowagie.text.pdf;
22

3-
import static org.hamcrest.MatcherAssert.assertThat;
4-
import static org.hamcrest.Matchers.equalTo;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
54

65
import com.lowagie.text.Element;
76
import com.lowagie.text.Paragraph;
@@ -34,21 +33,23 @@ List<DynamicTest> testCreateWithAllElementsInOneCell() {
3433

3534
PdfPTable result = PdfDocument.createInOneCell(mainParagraph);
3635
return Arrays.asList(
37-
DynamicTest.dynamicTest("row size should be 1", () -> assertThat(result.getRows().size(), equalTo(1))),
36+
DynamicTest.dynamicTest("row size should be 1",
37+
() -> assertEquals(1, result.getRows().size())),
3838
DynamicTest.dynamicTest("cell size should be 1", () -> {
3939
final PdfPCell[] cells = result.getRows().get(0).getCells();
40-
assertThat(cells.length, equalTo(1));
40+
assertEquals(1, cells.length);
4141
}),
4242
DynamicTest.dynamicTest("elements in cell should be 5",
43-
() -> assertThat(getCellElements(result).size(), equalTo(5))),
43+
() -> assertEquals(5, getCellElements(result).size())),
4444
DynamicTest.dynamicTest("element text should be '" + PARAGRAPH_TEXT_1 + "'",
45-
() -> assertThat(getCellElements(result).get(0).getChunks().toString(),
46-
equalTo(paragraph1.toString()))),
45+
() -> assertEquals(paragraph1.toString(),
46+
getCellElements(result).get(0).getChunks().toString())),
4747
DynamicTest.dynamicTest("element should be table",
48-
() -> assertThat(getCellElements(result).get(2), equalTo(table))),
48+
() -> assertEquals(table, getCellElements(result).get(2))),
4949
DynamicTest.dynamicTest("element text should be '" + PARAGRAPH_TEXT_2 + "'",
50-
() -> assertThat(getCellElements(result).get(3).getChunks().toString(),
51-
equalTo(paragraph2.toString()))));
50+
() -> assertEquals(paragraph2.toString(),
51+
getCellElements(result).get(3).getChunks().toString()
52+
)));
5253
}
5354

5455
private List<Element> getCellElements(PdfPTable result) {

openpdf/src/test/java/com/lowagie/text/pdf/parser/PdfTextExtractorTest.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package com.lowagie.text.pdf.parser;
22

3-
import static org.hamcrest.MatcherAssert.assertThat;
4-
import static org.hamcrest.Matchers.containsString;
5-
import static org.hamcrest.Matchers.emptyString;
6-
import static org.hamcrest.Matchers.equalToCompressingWhiteSpace;
7-
import static org.hamcrest.Matchers.is;
8-
import static org.hamcrest.Matchers.not;
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
95
import static org.junit.jupiter.api.Assertions.assertNotNull;
106
import static org.junit.jupiter.api.Assertions.assertTrue;
117

@@ -26,7 +22,6 @@
2622
import java.io.InputStream;
2723
import java.net.URL;
2824
import java.nio.file.Files;
29-
import org.junit.jupiter.api.Assertions;
3025
import org.junit.jupiter.api.Test;
3126

3227

@@ -68,12 +63,12 @@ protected static byte[] readDocument(final File file) throws IOException {
6863

6964
@Test
7065
void testPageExceeded() throws Exception {
71-
assertThat(getString("HelloWorldMeta.pdf", 5), is(emptyString()));
66+
assertEquals("", getString("HelloWorldMeta.pdf", 5));
7267
}
7368

7469
@Test
7570
void testInvalidPageNumber() throws Exception {
76-
assertThat(getString("HelloWorldMeta.pdf", 0), is(emptyString()));
71+
assertEquals("", getString("HelloWorldMeta.pdf", 0));
7772
}
7873

7974
@Test
@@ -88,7 +83,7 @@ void testZapfDingbatsFont() throws Exception {
8883
document.add(new Chunk("Greek", new Font(Font.ZAPFDINGBATS)));
8984
document.close();
9085
PdfTextExtractor pdfTextExtractor = new PdfTextExtractor(new PdfReader(byteArrayOutputStream.toByteArray()));
91-
Assertions.assertEquals("✧❒❅❅❋", pdfTextExtractor.getTextFromPage(1));
86+
assertEquals("✧❒❅❅❋", pdfTextExtractor.getTextFromPage(1));
9287
Document.compress = true;
9388
}
9489

@@ -105,7 +100,7 @@ void testSymbolFont() throws Exception {
105100
document.add(selector.process("ετε"));
106101
document.close();
107102
PdfTextExtractor pdfTextExtractor = new PdfTextExtractor(new PdfReader(byteArrayOutputStream.toByteArray()));
108-
Assertions.assertEquals("ετε", pdfTextExtractor.getTextFromPage(1));
103+
assertEquals("ετε", pdfTextExtractor.getTextFromPage(1));
109104
Document.compress = true;
110105
}
111106

@@ -129,7 +124,7 @@ void whenTrunkedWordsInChunks_expectsFullWordAsExtraction() throws IOException {
129124
// when
130125
final String extracted = new PdfTextExtractor(new PdfReader(pdfBytes)).getTextFromPage(1);
131126
// then
132-
assertThat(extracted, is("trunked"));
127+
assertEquals("trunked", extracted);
133128
}
134129

135130
@Test
@@ -142,7 +137,7 @@ void getTextFromPageWithPhrases_expectsNoAddedSpace() throws IOException {
142137
// when
143138
final String extracted = new PdfTextExtractor(new PdfReader(pdfBytes)).getTextFromPage(1);
144139
// then
145-
assertThat(extracted, is("Phrase begin. Phrase End."));
140+
assertEquals("Phrase begin. Phrase End.", extracted);
146141
}
147142

148143
@Test
@@ -159,8 +154,9 @@ void getTextFromPageWithParagraphs_expectsTextHasNoMultipleSpaces() throws IOExc
159154
// when
160155
final String extracted = new PdfTextExtractor(new PdfReader(pdfBytes)).getTextFromPage(1);
161156
// then
162-
assertThat(extracted, equalToCompressingWhiteSpace(expected));
163-
assertThat(extracted, not(containsString(" ")));
157+
assertFalse(extracted.contains(" "));
158+
// ignore all white spaces
159+
assertEquals(expected.replaceAll("\\s+", ""), extracted.replaceAll("\\s+", ""));
164160
}
165161

166162
@Test
@@ -175,7 +171,7 @@ void getTextFromPageInTablesWithSingleWords_expectsWordsAreSeparatedBySpaces()
175171
// when
176172
final String extracted = new PdfTextExtractor(new PdfReader(pdfBytes)).getTextFromPage(1);
177173
// then
178-
assertThat(extracted, is("One Two Three"));
174+
assertEquals("One Two Three", extracted);
179175
}
180176

181177
private String getString(String fileName, int pageNumber) throws Exception {

pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
<!-- test-dependencies -->
9898
<assertj.version>3.27.3</assertj.version>
9999
<checkstyle.version>10.23.1</checkstyle.version>
100-
<hamcrest.version>3.0</hamcrest.version>
101100
<jacoco-maven-plugin.version>0.8.13</jacoco-maven-plugin.version>
102101
<junit.version>5.12.2</junit.version>
103102
<mockito4.version>4.11.0</mockito4.version>
@@ -170,12 +169,6 @@
170169
<version>${junit.version}</version>
171170
<scope>test</scope>
172171
</dependency>
173-
<dependency>
174-
<groupId>org.hamcrest</groupId>
175-
<artifactId>hamcrest</artifactId>
176-
<version>${hamcrest.version}</version>
177-
<scope>test</scope>
178-
</dependency>
179172
</dependencies>
180173
</dependencyManagement>
181174

0 commit comments

Comments
 (0)