X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneInserterTest.java;h=f9905000f7f3622c0535c7f0a933d9916922b1cf;hb=b5773d0578a01a950e0ff48e1f6631667ddfa998;hp=23d9513037bb7f4c27c4f37246c3df7cbd9cb189;hpb=d9d178b845ae83155f22a52e4ea697359864883c;p=Sone.git diff --git a/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java b/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java index 23d9513..f990500 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneInserterTest.java @@ -1,17 +1,16 @@ package net.pterodactylus.sone.core; -import static com.google.common.base.Optional.of; import static com.google.common.io.ByteStreams.toByteArray; -import static com.google.common.util.concurrent.MoreExecutors.sameThreadExecutor; +import static com.google.common.util.concurrent.MoreExecutors.directExecutor; import static java.lang.System.currentTimeMillis; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -49,8 +48,6 @@ import org.mockito.stubbing.Answer; /** * Unit test for {@link SoneInserter} and its subclasses. - * - * @author David ‘Bombe’ Roden */ public class SoneInserterTest { @@ -62,12 +59,12 @@ public class SoneInserterTest { public void setupCore() { UpdateChecker updateChecker = mock(UpdateChecker.class); when(core.getUpdateChecker()).thenReturn(updateChecker); - when(core.getSone(anyString())).thenReturn(Optional.absent()); + when(core.getSone(anyString())).thenReturn(null); } @Test public void insertionDelayIsForwardedToSoneInserter() { - EventBus eventBus = new AsyncEventBus(sameThreadExecutor()); + EventBus eventBus = new AsyncEventBus(directExecutor()); eventBus.register(new SoneInserter(core, eventBus, freenetInterface, "SoneId")); eventBus.post(new InsertionDelayChangedEvent(15)); assertThat(SoneInserter.getInsertionDelay().get(), is(15)); @@ -78,7 +75,7 @@ public class SoneInserterTest { when(sone.getInsertUri()).thenReturn(insertUri); when(sone.getFingerprint()).thenReturn(fingerprint); when(sone.getRootAlbum()).thenReturn(mock(Album.class)); - when(core.getSone(anyString())).thenReturn(of(sone)); + when(core.getSone(anyString())).thenReturn(sone); return sone; } @@ -133,9 +130,9 @@ public class SoneInserterTest { verify(freenetInterface).insertDirectory(eq(insertUri), any(HashMap.class), eq("index.html")); verify(eventBus, times(2)).post(soneEvents.capture()); assertThat(soneEvents.getAllValues().get(0), instanceOf(SoneInsertingEvent.class)); - assertThat(soneEvents.getAllValues().get(0).sone(), is(sone)); + assertThat(soneEvents.getAllValues().get(0).getSone(), is(sone)); assertThat(soneEvents.getAllValues().get(1), instanceOf(SoneInsertedEvent.class)); - assertThat(soneEvents.getAllValues().get(1).sone(), is(sone)); + assertThat(soneEvents.getAllValues().get(1).getSone(), is(sone)); } @Test @@ -159,9 +156,9 @@ public class SoneInserterTest { verify(freenetInterface).insertDirectory(eq(insertUri), any(HashMap.class), eq("index.html")); verify(eventBus, times(2)).post(soneEvents.capture()); assertThat(soneEvents.getAllValues().get(0), instanceOf(SoneInsertingEvent.class)); - assertThat(soneEvents.getAllValues().get(0).sone(), is(sone)); + assertThat(soneEvents.getAllValues().get(0).getSone(), is(sone)); assertThat(soneEvents.getAllValues().get(1), instanceOf(SoneInsertedEvent.class)); - assertThat(soneEvents.getAllValues().get(1).sone(), is(sone)); + assertThat(soneEvents.getAllValues().get(1).getSone(), is(sone)); verify(core, never()).touchConfiguration(); } @@ -209,9 +206,9 @@ public class SoneInserterTest { verify(freenetInterface).insertDirectory(eq(insertUri), any(HashMap.class), eq("index.html")); verify(eventBus, times(2)).post(soneEvents.capture()); assertThat(soneEvents.getAllValues().get(0), instanceOf(SoneInsertingEvent.class)); - assertThat(soneEvents.getAllValues().get(0).sone(), is(sone)); + assertThat(soneEvents.getAllValues().get(0).getSone(), is(sone)); assertThat(soneEvents.getAllValues().get(1), instanceOf(SoneInsertAbortedEvent.class)); - assertThat(soneEvents.getAllValues().get(1).sone(), is(sone)); + assertThat(soneEvents.getAllValues().get(1).getSone(), is(sone)); verify(core, never()).touchConfiguration(); } @@ -223,7 +220,7 @@ public class SoneInserterTest { new SoneInserter(core, eventBus, freenetInterface, "SoneId", soneModificationDetector, 1); when(soneModificationDetector.isEligibleForInsert()).thenReturn(true); - when(core.getSone("SoneId")).thenReturn(Optional.absent()); + when(core.getSone("SoneId")).thenReturn(null); soneInserter.serviceRun(); } @@ -251,7 +248,7 @@ public class SoneInserterTest { @Test public void templateIsRenderedCorrectlyForManifestElement() throws IOException { - Map soneProperties = new HashMap(); + Map soneProperties = new HashMap<>(); soneProperties.put("id", "SoneId"); ManifestCreator manifestCreator = new ManifestCreator(core, soneProperties); long now = currentTimeMillis(); @@ -267,7 +264,7 @@ public class SoneInserterTest { @Test public void invalidTemplateReturnsANullManifestElement() { - Map soneProperties = new HashMap(); + Map soneProperties = new HashMap<>(); ManifestCreator manifestCreator = new ManifestCreator(core, soneProperties); assertThat(manifestCreator.createManifestElement("test.txt", "plain/text; charset=utf-8", @@ -277,7 +274,7 @@ public class SoneInserterTest { @Test public void errorWhileRenderingTemplateReturnsANullManifestElement() { - Map soneProperties = new HashMap(); + Map soneProperties = new HashMap<>(); ManifestCreator manifestCreator = new ManifestCreator(core, soneProperties); when(core.toString()).thenThrow(NullPointerException.class); assertThat(manifestCreator.createManifestElement("test.txt",