+ protected void addPostReply(String postReplyId, PostReply postReply) {
+ if (postReply.getPostId() != null) {
+ postReplies.put(postReply.getPostId(), postReply);
+ }
+ when(core.getPostReply(postReplyId)).thenReturn(Optional.fromNullable(postReply));
+ }
+
+ protected void addSone(String soneId, Sone sone) {
+ sones.put(soneId, sone);
+ }
+
+ protected void addLocalSone(String soneId, Sone sone) {
+ when(core.getLocalSone(eq(soneId))).thenReturn(sone);
+ localSones.add(sone);
+ }
+
+ protected void addOwnIdentity(OwnIdentity ownIdentity) {
+ ownIdentities.add(ownIdentity);
+ }
+
+ protected void addAlbum(String albumId, Album album) {
+ when(core.getAlbum(eq(albumId))).thenReturn(album);
+ }
+
+ protected void addImage(String imageId, Image image) {
+ when(core.getImage(eq(imageId))).thenReturn(image);
+ when(core.getImage(eq(imageId), anyBoolean())).thenReturn(image);
+ }
+
+ protected void addTemporaryImage(String imageId, TemporaryImage temporaryImage) {
+ when(core.getTemporaryImage(eq(imageId))).thenReturn(temporaryImage);
+ }
+
+ protected byte[] getResponseBytes() throws IOException {
+ response.getContent().close();
+ try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+ ByteStreams.copy(responseInputStream, outputStream);
+ return outputStream.toByteArray();
+ }
+ }
+
+ protected void addNotification(String notificationId, Notification notification) {
+ when(webInterface.getNotification(eq(notificationId))).thenReturn(Optional.of(notification));
+ }
+
+ protected void verifyRedirect(String target) throws RedirectException {
+ expectedException.expect(redirectsTo(target));
+ getPage().handleRequest(freenetRequest, templateContext);
+ }
+
+ protected void verifyRedirect(String target, Runnable verification) throws RedirectException {
+ expectedException.expect(redirectsTo(target));
+ try {
+ getPage().handleRequest(freenetRequest, templateContext);
+ fail();
+ } finally {
+ verification.run();
+ }
+ }
+