From: David ‘Bombe’ Roden Date: Tue, 30 Sep 2014 19:21:39 +0000 (+0200) Subject: Add more tests for the Sone inserter. X-Git-Tag: 0.9-rc1^2~3^2~80 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=b2b444224f9ad00d75bf58d07efb554dbdcb4226;p=Sone.git Add more tests for the Sone inserter. --- diff --git a/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java b/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java index d43f383..c44ced6 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java @@ -12,6 +12,7 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -221,4 +222,37 @@ public class SoneInserterTest { verify(core, never()).touchConfiguration(); } + @Test + public void soneInserterExitsIfSoneIsUnknown() { + SoneModificationDetector soneModificationDetector = + mock(SoneModificationDetector.class); + SoneInserter soneInserter = + new SoneInserter(core, eventBus, freenetInterface, "SoneId", + soneModificationDetector, 1); + when(soneModificationDetector.isEligibleForInsert()).thenReturn(true); + when(core.getSone("SoneId")).thenReturn(Optional.absent()); + soneInserter.serviceRun(); + } + + @Test + public void soneInserterCatchesExceptionAndContinues() { + SoneModificationDetector soneModificationDetector = + mock(SoneModificationDetector.class); + final SoneInserter soneInserter = + new SoneInserter(core, eventBus, freenetInterface, "SoneId", + soneModificationDetector, 1); + Answer> stopInserterAndThrowException = + new Answer>() { + @Override + public Optional answer( + InvocationOnMock invocation) { + soneInserter.stop(); + throw new NullPointerException(); + } + }; + when(soneModificationDetector.isEligibleForInsert()).thenAnswer( + stopInserterAndThrowException); + soneInserter.serviceRun(); + } + }