From b2b444224f9ad00d75bf58d07efb554dbdcb4226 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 30 Sep 2014 21:21:39 +0200 Subject: [PATCH] Add more tests for the Sone inserter. --- .../pterodactylus/sone/core/SoneInserterTest.java | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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(); + } + } -- 2.7.4