Skip to content

Commit

Permalink
[TIKA-2392] Fix the rest of potential bugs and 2 new ones that may tr…
Browse files Browse the repository at this point in the history
…igger NullPointerException + add test case
  • Loading branch information
longphan98 committed May 25, 2022
1 parent 9150753 commit bf956f9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tika-app/src/main/java/org/apache/tika/gui/TikaGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ public File requestSave(String embeddedName) throws IOException {

int splitAt = embeddedName.lastIndexOf('.');
if (splitAt > 0) {
embeddedName.substring(splitAt);
embeddedName = embeddedName.substring(splitAt);
}

File tmp = File.createTempFile("tika-embedded-", suffix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public void setUp() throws Exception {
testDirectory = tempDir;
System.out.println(testDirectory.toAbsolutePath());
try (InputStream is = this.getClass().getResourceAsStream(TEST_CLASSPATH)) {
assert is != null;
Files.copy(is, testDirectory.resolve(TEST_HTML));
}
try (InputStream is = this.getClass().getResourceAsStream(TEST_CLASSPATH)) {
assert is != null;
Files.copy(is, testDirectory.resolve(TEST_UNRECOGNISED_EXTENSION));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public String getFilter() {
* Default value is triangle.
*/
public void setFilter(String filter) {
if (filter.equals(null)) {
if (filter == null) {
throw new IllegalArgumentException(
"Filter value cannot be null. Valid values are point, hermite, " +
"cubic, box, gaussian, catrom, triangle, quadratic and mitchell.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
*/
package org.apache.tika.parser.ocr;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
Expand All @@ -31,6 +26,8 @@
import org.apache.tika.config.TikaConfig;
import org.apache.tika.parser.CompositeParser;

import static org.junit.jupiter.api.Assertions.*;

public class TesseractOCRConfigTest extends TikaTest {

@Test
Expand All @@ -46,7 +43,7 @@ public void testNoConfig() throws Exception {
assertEquals("gray", config.getColorspace(), "Invalid default colorpsace value");
assertEquals("triangle", config.getFilter(), "Invalid default filter value");
assertEquals(200, config.getResize(), "Invalid default resize value");
assertEquals(false, config.isApplyRotation(), "Invalid default applyRotation value");
assertFalse(config.isApplyRotation(), "Invalid default applyRotation value");
}

@Test
Expand All @@ -67,7 +64,7 @@ public void testPartialConfig() throws Exception {
assertEquals(8, config.getDepth(), "Invalid overridden depth value");
assertEquals("box", config.getFilter(), "Invalid overridden filter value");
assertEquals(300, config.getResize(), "Invalid overridden resize value");
assertEquals(false, config.isApplyRotation(), "Invalid default applyRotation value");
assertFalse(config.isApplyRotation(), "Invalid default applyRotation value");
}

@Test
Expand All @@ -89,7 +86,7 @@ public void testFullConfig() throws Exception {
assertEquals(8, config.getDepth(), "Invalid overridden depth value");
assertEquals("box", config.getFilter(), "Invalid overridden filter value");
assertEquals(300, config.getResize(), "Invalid overridden resize value");
assertEquals(true, config.isApplyRotation(), "Invalid default applyRotation value");
assertTrue(config.isApplyRotation(), "Invalid default applyRotation value");
}

@Test
Expand Down Expand Up @@ -250,6 +247,14 @@ public void testBadColorSpace() {
});
}

@Test
public void testNullFilter() {
TesseractOCRConfig config = new TesseractOCRConfig();
assertThrows(IllegalArgumentException.class, () -> {
config.setFilter(null);
});
}

@Test
public void testUpdatingConfigs() throws Exception {
TesseractOCRConfig configA = new TesseractOCRConfig();
Expand Down

0 comments on commit bf956f9

Please sign in to comment.