diff --git a/Core/test/unit/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/UserActivitySummaryTests.java b/Core/test/unit/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/UserActivitySummaryTests.java index 9b1cc5e08e..738d518cdb 100644 --- a/Core/test/unit/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/UserActivitySummaryTests.java +++ b/Core/test/unit/src/org/sleuthkit/autopsy/datasourcesummary/datamodel/UserActivitySummaryTests.java @@ -92,7 +92,6 @@ public class UserActivitySummaryTests { public ExpectedException thrown = ExpectedException.none(); private static BlackboardArtifact.Type ACCOUNT_TYPE = new BlackboardArtifact.Type(ARTIFACT_TYPE.TSK_ACCOUNT); - private static BlackboardAttribute.Type TYPE_ACCOUNT_TYPE = new BlackboardAttribute.Type(ATTRIBUTE_TYPE.TSK_ACCOUNT_TYPE); @@ -123,17 +122,13 @@ public class UserActivitySummaryTests { private void testMinCount(DataFunction funct, String id) throws TskCoreException, NoServiceProviderException, TranslationException, SleuthkitCaseProviderException { - Pair tskPair = getArtifactsTSKMock(null); - UserActivitySummary summary = getTestClass(tskPair.getLeft(), false, null); - thrown.expect(IllegalArgumentException.class); - funct.retrieve(summary, TskMockUtils.mockDataSource(1), -1); - verify(tskPair.getRight(), never()).getArtifacts(anyInt(), anyInt()); - - Pair tskPair2 = getArtifactsTSKMock(null); - UserActivitySummary summary2 = getTestClass(tskPair.getLeft(), false, null); - thrown.expect(IllegalArgumentException.class); - funct.retrieve(summary2, TskMockUtils.mockDataSource(1), -1); - verify(tskPair.getRight(), never()).getArtifacts(anyInt(), anyInt()); + for (int nonPositiveValue : new int[]{ -1, 0}) { + Pair tskPair = getArtifactsTSKMock(null); + UserActivitySummary summary = getTestClass(tskPair.getLeft(), false, null); + thrown.expect(IllegalArgumentException.class); + funct.retrieve(summary, TskMockUtils.mockDataSource(1), nonPositiveValue); + verify(tskPair.getRight(), never()).getArtifacts(anyInt(), anyInt()); + } } @Test diff --git a/Core/test/unit/src/org/sleuthkit/autopsy/testutils/TskMockUtils.java b/Core/test/unit/src/org/sleuthkit/autopsy/testutils/TskMockUtils.java index 0916492ba4..51527f7962 100644 --- a/Core/test/unit/src/org/sleuthkit/autopsy/testutils/TskMockUtils.java +++ b/Core/test/unit/src/org/sleuthkit/autopsy/testutils/TskMockUtils.java @@ -18,15 +18,14 @@ */ package org.sleuthkit.autopsy.testutils; +import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.Map; import java.util.function.Function; -import java.util.logging.Level; import java.util.stream.Collectors; import java.util.stream.Stream; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.sleuthkit.autopsy.coreutils.Logger; @@ -126,11 +125,25 @@ public class TskMockUtils { return translationService; } - public static Logger getTSKLogger() { - Logger logger = mock(Logger.class); - doNothing().when(logger).log(any(Level.class), anyString(), any(Throwable.class)); - doNothing().when(logger).log(any(Level.class), anyString()); - return logger; + + /** + * + * @param loggerName + * @return + * @throws InstantiationException + * @throws NoSuchMethodException + * @throws SecurityException + */ + public static Logger getTSKLogger(String loggerName) + throws InstantiationException, NoSuchMethodException, SecurityException { + + // The logger doesn't appear to respond well to mocking with mockito. + // It appears that the issue may have to do with mocking methods in the java.* packages + // since the autopsy logger extends the java.util.logging.Logger class: + // https://javadoc.io/static/org.mockito/mockito-core/3.5.13/org/mockito/Mockito.html#39 + Constructor constructor = Logger.class.getConstructor(String.class, String.class); + constructor.setAccessible(true); + return constructor.newInstance(loggerName, null); } private TskMockUtils() {