This is an automated email from the ASF dual-hosted git repository.

claude pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/creadur-rat.git


The following commit(s) were added to refs/heads/master by this push:
     new 29b35925 RAT-178: Test binary guesser errors (#407)
29b35925 is described below

commit 29b35925c1ceabfadfc079dc5e6f82b06f26e6d2
Author: Claude Warren <[email protected]>
AuthorDate: Tue Dec 3 10:41:19 2024 +0000

    RAT-178: Test binary guesser errors (#407)
    
    * Added tests to TikaProcessorTests and DefaultAnalyserFactoryTest
    
    * RAT-178: Add tests for processing runs with non-existing or unreadable 
files
    
    * RAT-178: Modify changelog entry as it is our binary guesser
    
    ---------
    
    Co-authored-by: P. Ottlinger <[email protected]>
---
 .../apache/rat/analysis/DefaultAnalyserFactory.java  |  7 +++++--
 .../rat/analysis/DefaultAnalyserFactoryTest.java     | 20 +++++++++++++++++---
 .../org/apache/rat/analysis/TikaProcessorTest.java   | 10 ++++++++--
 src/changes/changes.xml                              |  3 +++
 4 files changed, 33 insertions(+), 7 deletions(-)

diff --git 
a/apache-rat-core/src/main/java/org/apache/rat/analysis/DefaultAnalyserFactory.java
 
b/apache-rat-core/src/main/java/org/apache/rat/analysis/DefaultAnalyserFactory.java
index 4095f066..b6005083 100644
--- 
a/apache-rat-core/src/main/java/org/apache/rat/analysis/DefaultAnalyserFactory.java
+++ 
b/apache-rat-core/src/main/java/org/apache/rat/analysis/DefaultAnalyserFactory.java
@@ -32,6 +32,7 @@ import org.apache.rat.document.RatDocumentAnalysisException;
 import org.apache.rat.license.ILicense;
 import org.apache.rat.license.LicenseSetFactory;
 import org.apache.rat.utils.DefaultLog;
+import org.apache.rat.utils.Log;
 import org.apache.rat.walker.ArchiveWalker;
 
 /**
@@ -52,8 +53,10 @@ public final class DefaultAnalyserFactory {
         if (licenses.isEmpty()) {
             throw new ConfigurationException("At least one license must be 
defined");
         }
-        DefaultLog.getInstance().debug("Licenses in Test");
-        licenses.forEach(DefaultLog.getInstance()::debug);
+        if (DefaultLog.getInstance().isEnabled(Log.Level.DEBUG)) {
+            DefaultLog.getInstance().debug("Currently active Licenses are:");
+            licenses.forEach(DefaultLog.getInstance()::debug);
+        }
         return new DefaultAnalyser(configuration, licenses);
     }
 
diff --git 
a/apache-rat-core/src/test/java/org/apache/rat/analysis/DefaultAnalyserFactoryTest.java
 
b/apache-rat-core/src/test/java/org/apache/rat/analysis/DefaultAnalyserFactoryTest.java
index 7e863290..b167052a 100644
--- 
a/apache-rat-core/src/test/java/org/apache/rat/analysis/DefaultAnalyserFactoryTest.java
+++ 
b/apache-rat-core/src/test/java/org/apache/rat/analysis/DefaultAnalyserFactoryTest.java
@@ -20,6 +20,7 @@ package org.apache.rat.analysis;
 
 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;
 
 import java.io.File;
@@ -35,6 +36,7 @@ import org.apache.rat.document.DocumentNameMatcher;
 import org.apache.rat.document.IDocumentAnalyser;
 import org.apache.rat.document.DocumentName;
 import org.apache.rat.document.FileDocument;
+import org.apache.rat.document.RatDocumentAnalysisException;
 import org.apache.rat.report.claim.SimpleXmlClaimReporter;
 import org.apache.rat.report.xml.writer.XmlWriter;
 import org.apache.rat.test.utils.Resources;
@@ -109,7 +111,7 @@ public class DefaultAnalyserFactoryTest {
         assertEquals("application/java-archive", 
document.getMetaData().getMediaType().toString());
     }
 
-    private static Stream<Arguments> archivesAbsenceTestData() {
+    private static Stream<Arguments> archiveProcessingTestData() {
         List<Arguments> lst = new ArrayList<>();
         lst.add(Arguments.of(ReportConfiguration.Processing.NOTIFICATION, 0));
         lst.add(Arguments.of(ReportConfiguration.Processing.PRESENCE, 2));
@@ -118,8 +120,8 @@ public class DefaultAnalyserFactoryTest {
     }
 
     @ParameterizedTest
-    @MethodSource("archivesAbsenceTestData")
-    public void archivesAbsenceTest(ReportConfiguration.Processing 
archiveProcessing, int expectedLicenseCount) throws Exception {
+    @MethodSource("archiveProcessingTestData")
+    public void archiveProcessingTest(ReportConfiguration.Processing 
archiveProcessing, int expectedLicenseCount) throws Exception {
         final Document document = new FileDocument(basedir,
                 Resources.getResourceFile("/elements/dummy.jar"), 
DocumentNameMatcher.MATCHES_ALL);
         Defaults defaults = Defaults.builder().build();
@@ -133,6 +135,18 @@ public class DefaultAnalyserFactoryTest {
         assertEquals(expectedLicenseCount, 
document.getMetaData().licenses().count());
     }
 
+    @Test
+    public void missingFileTest() {
+        final Document document = new FileDocument(
+                new File("/elements/not_a_real_file"), 
DocumentNameMatcher.MATCHES_ALL);
+        Defaults defaults = Defaults.builder().build();
+        ReportConfiguration config = new ReportConfiguration();
+        config.setFrom(defaults);
+        analyser = DefaultAnalyserFactory.createDefaultAnalyser(config);
+        assertThrows(RatDocumentAnalysisException.class, () -> 
analyser.analyse(document));
+    }
+
+
     @Test
     public void archiveTypeAnalyser() throws Exception {
         final Document document = new FileDocument(basedir,
diff --git 
a/apache-rat-core/src/test/java/org/apache/rat/analysis/TikaProcessorTest.java 
b/apache-rat-core/src/test/java/org/apache/rat/analysis/TikaProcessorTest.java
index ae8123e9..5017622d 100644
--- 
a/apache-rat-core/src/test/java/org/apache/rat/analysis/TikaProcessorTest.java
+++ 
b/apache-rat-core/src/test/java/org/apache/rat/analysis/TikaProcessorTest.java
@@ -49,7 +49,7 @@ public class TikaProcessorTest {
      * because the encoding of the stream was different from the
      * platform's default encoding.
      *
-     * @see "RAT-81"
+     * @see <a href="https://issues.apache.org/jira/browse/RAT-81";>RAT-81</a>
      */
     @Test
     public void RAT81() {
@@ -86,6 +86,12 @@ public class TikaProcessorTest {
         assertEquals(Document.Type.STANDARD, 
doc.getMetaData().getDocumentType());
     }
 
+    @Test
+    public void RAT178Test() {
+        FileDocument doc = new FileDocument(new File("/not_a_real_file"), 
DocumentNameMatcher.MATCHES_ALL);
+        assertThrows(RatDocumentAnalysisException.class, () 
->TikaProcessor.process(doc));
+    }
+
     @Test
     public void missNamedBinaryTest() throws Exception {
         FileDocument doc = mkDocument("/binaries/Image-png.not");
@@ -131,7 +137,7 @@ public class TikaProcessorTest {
                 }
             }
         }
-        System.out.println( "untested mime types");
+        System.out.println("untested mime types");
         unseenMime.keySet().forEach(System.out::println);
         for (Document.Type type : Document.Type.values()) {
             System.out.format("Tested %s %s files%n", 
statistic.getCounter(type), type);
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e4874f34..48472b3a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -72,6 +72,9 @@ The <action> type attribute can be one of:
     </release>
     -->
     <release version="0.17-SNAPSHOT" date="xxxx-yy-zz" description="Current 
SNAPSHOT - release to be done">
+      <action issue="RAT-178" type="add" dev="claudenw">
+        Added tests to TikaProcessorTests and DefaultAnalyserFactoryTest to 
properly handle non-existent and unreadable files during processing runs of our 
BinaryGuesser.
+      </action>
       <action issue="RAT-405" type="add" dev="claudenw">
         Do not show sample output of scanned files in XML anymore. As files 
are report different tooling can be used to edit/check the files.
       </action>

Reply via email to