diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2025-01-15 15:39:34 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2025-01-17 00:47:38 +0100 |
commit | 524fdd47f97cc10924b8d246267688a953f626bc (patch) | |
tree | 3fab7334d10ea99f86d941dceea54eed9344fc86 | |
parent | 1af00e9d9b445265b2c00ce28a3927f35591afb9 (diff) | |
download | jgit-524fdd47f97cc10924b8d246267688a953f626bc.tar.gz jgit-524fdd47f97cc10924b8d246267688a953f626bc.zip |
Fix ObjectDirectoryTest#testOpenLooseObjectPropagatesIOExceptions
By instrumenting "LooseObjects#open" with print statements (since
debugging mocks doesn't work in Eclipse) I found that the constructor
"LooseObjects(Config, File)" which defaults "core.trustFolderStat" to
"true" isn't used when mocking LooseObjects. Hence
"core.trustFolderStat" is in fact "false" in the mocked LooseObjects
object.
Make this explicit by configuring "trustFolderStat=false" in a real
"LooseObjects" object and only mock its method "#getObjectLoader" using
a spy.
Change-Id: I2f870637db818c2e89c1c2a174bf78bd572a367a
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java index d1342c0fbd..7d298ee6f1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java @@ -49,7 +49,9 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import java.io.File; @@ -66,6 +68,7 @@ import java.util.concurrent.Future; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; @@ -221,19 +224,21 @@ public class ObjectDirectoryTest extends RepositoryTestCase { verify(unpackedObjectCacheMock).remove(id); } - @Test + @Test(expected = IOException.class) public void testOpenLooseObjectPropagatesIOExceptions() throws Exception { ObjectId id = ObjectId .fromString("873fb8d667d05436d728c52b1d7a09528e6eb59b"); WindowCursor curs = new WindowCursor(db.getObjectDatabase()); - LooseObjects mock = mock(LooseObjects.class); + Config config = new Config(); + config.setString("core", null, "trustFolderStat", "false"); + LooseObjects spy = spy(new LooseObjects(config, + db.getObjectDatabase().getDirectory())); - Mockito.when(mock.getObjectLoader(any(), any(), any())) - .thenThrow(new IOException("some IO failure")); - Mockito.when(mock.open(curs, id)).thenCallRealMethod(); + doThrow(new IOException("some IO failure")).when(spy) + .getObjectLoader(any(), any(), any()); - assertThrows(IOException.class, () -> mock.open(curs, id)); + spy.open(curs, id); } @Test |