Remove unnecessary stubbings from CachingContentStoreTest

This commit is contained in:
Sara Aspery
2025-02-25 14:48:11 +00:00
parent 99fce928fa
commit 6c08c3cff2

View File

@@ -2,7 +2,7 @@
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* Copyright (C) 2005 - 2025 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
@@ -25,13 +25,11 @@
*/
package org.alfresco.repo.content.caching;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
@@ -51,6 +49,13 @@ import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.alfresco.repo.content.ContentContext;
import org.alfresco.repo.content.ContentRestoreParams;
import org.alfresco.repo.content.ContentStore;
@@ -62,12 +67,6 @@ import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentStreamListener;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.DirectAccessUrl;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
/**
* Tests for the CachingContentStore class. Tests use mock backing store and cache.
@@ -87,7 +86,6 @@ public class CachingContentStoreTest
@Mock
private ContentCache cache;
@Before
public void setUp() throws Exception
{
@@ -98,7 +96,6 @@ public class CachingContentStoreTest
cachedContent = mock(ContentReader.class, "cachedContent");
}
@Test
public void getReaderForItemInCache()
{
@@ -111,7 +108,6 @@ public class CachingContentStoreTest
verify(backingStore, never()).getReader(anyString());
}
@Test
// Item isn't in cache, so will be cached and returned.
public void getReaderForItemMissingFromCache()
@@ -134,7 +130,6 @@ public class CachingContentStoreTest
verify(backingStore, only()).getReader("url");
}
@Test
public void getReaderForItemMissingFromCacheWillGiveUpAfterRetrying()
{
@@ -151,13 +146,10 @@ public class CachingContentStoreTest
assertSame(returnedReader, sourceContent);
}
@Test
public void getReaderForItemMissingFromCacheWillRetryAndCanSucceed()
{
when(cache.getReader("url")).
thenThrow(new CacheMissException("url")).
thenReturn(cachedContent);
when(cache.getReader("url")).thenThrow(new CacheMissException("url")).thenReturn(cachedContent);
when(backingStore.getReader("url")).thenReturn(sourceContent);
when(cache.put("url", sourceContent)).thenReturn(true);
@@ -166,18 +158,15 @@ public class CachingContentStoreTest
assertSame(returnedReader, cachedContent);
}
@Test
public void getReaderForItemMissingFromCacheButNoContentToCache()
{
when(cache.getReader("url")).thenThrow(new CacheMissException("url"));
when(backingStore.getReader("url")).thenReturn(sourceContent);
when(cache.put("url", sourceContent)).thenReturn(false);
cachingStore.getReader("url");
}
@Test
// When attempting to read uncached content.
public void quotaManagerCanVetoCacheFileWriting()
@@ -195,7 +184,6 @@ public class CachingContentStoreTest
verify(quota, never()).afterWritingCacheFile(anyLong());
}
@Test
public void getWriterWhenNotCacheOnInbound()
{
@@ -212,7 +200,6 @@ public class CachingContentStoreTest
verify(quota, never()).afterWritingCacheFile(anyLong());
}
@Test
public void getWriterWhenCacheOnInbound() throws ContentIOException, IOException
{
@@ -246,7 +233,6 @@ public class CachingContentStoreTest
verify(quota).afterWritingCacheFile(54321L);
}
@Test
// When attempting to perform write-through caching, i.e. cacheOnInbound = true
public void quotaManagerCanVetoInboundCaching()
@@ -266,7 +252,6 @@ public class CachingContentStoreTest
verify(quota, never()).afterWritingCacheFile(anyLong());
}
@Test
public void quotaManagerCanRequestFileDeletionFromCacheAfterWrite()
{
@@ -321,7 +306,6 @@ public class CachingContentStoreTest
// Don't veto writing the cache file.
when(quota.beforeWritingCacheFile(1274L)).thenReturn(true);
// Do request cache file deletion.
when(quota.afterWritingCacheFile(1234L)).thenReturn(false);
ContentReader returnedReader = cachingStore.getReader("url");
@@ -360,7 +344,6 @@ public class CachingContentStoreTest
arg.getValue().contentStreamClosed();
}
@Test
public void encodingAttrsCopiedToBackingStoreWriter()
{
@@ -439,7 +422,6 @@ public class CachingContentStoreTest
assertFalse(cachingStore.isContentUrlSupported("url"));
}
@Test
public void delegatedIsWriteSupported()
{
@@ -450,7 +432,6 @@ public class CachingContentStoreTest
assertFalse(cachingStore.isWriteSupported());
}
@Test
public void delegatedGetSpaceFree()
{
@@ -458,7 +439,6 @@ public class CachingContentStoreTest
assertEquals(124L, cachingStore.getSpaceFree());
}
@Test
public void delegatedGetSpaceTotal()
{
@@ -466,7 +446,6 @@ public class CachingContentStoreTest
assertEquals(4234L, cachingStore.getSpaceTotal());
}
@Test
public void delegatedGetRootLocation()
{
@@ -474,7 +453,6 @@ public class CachingContentStoreTest
assertEquals("/random/root/dir", cachingStore.getRootLocation());
}
@Test
public void delegatedExists()
{
@@ -485,7 +463,6 @@ public class CachingContentStoreTest
assertFalse(cachingStore.exists("url"));
}
@Test
public void delegatedDelete()
{