Inject ImageSizeCalculator.

parent fe7dfa72
Pipeline #3624 passed with stage
in 8 minutes and 47 seconds
...@@ -4,6 +4,7 @@ import org.briarproject.bramble.BrambleAndroidModule; ...@@ -4,6 +4,7 @@ import org.briarproject.bramble.BrambleAndroidModule;
import org.briarproject.bramble.BrambleCoreModule; import org.briarproject.bramble.BrambleCoreModule;
import org.briarproject.bramble.account.BriarAccountModule; import org.briarproject.bramble.account.BriarAccountModule;
import org.briarproject.briar.BriarCoreModule; import org.briarproject.briar.BriarCoreModule;
import org.briarproject.briar.android.attachment.AttachmentModule;
import org.briarproject.briar.android.navdrawer.NavDrawerActivityTest; import org.briarproject.briar.android.navdrawer.NavDrawerActivityTest;
import javax.inject.Singleton; import javax.inject.Singleton;
...@@ -13,6 +14,7 @@ import dagger.Component; ...@@ -13,6 +14,7 @@ import dagger.Component;
@Singleton @Singleton
@Component(modules = { @Component(modules = {
AppModule.class, AppModule.class,
AttachmentModule.class,
BriarCoreModule.class, BriarCoreModule.class,
BrambleAndroidModule.class, BrambleAndroidModule.class,
BriarAccountModule.class, BriarAccountModule.class,
......
...@@ -47,9 +47,10 @@ public class AttachmentRetrieverIntegrationTest { ...@@ -47,9 +47,10 @@ public class AttachmentRetrieverIntegrationTest {
); );
private final MessageId msgId = new MessageId(getRandomId()); private final MessageId msgId = new MessageId(getRandomId());
private final ImageHelper imageHelper = new ImageHelperImpl();
private final AttachmentRetriever retriever = private final AttachmentRetriever retriever =
new AttachmentRetrieverImpl(null, dimensions, new AttachmentRetrieverImpl(null, dimensions, imageHelper,
new ImageHelperImpl()); new ImageSizeCalculator(imageHelper));
@Test @Test
public void testSmallJpegImage() throws Exception { public void testSmallJpegImage() throws Exception {
......
...@@ -39,10 +39,11 @@ class AttachmentRetrieverImpl implements AttachmentRetriever { ...@@ -39,10 +39,11 @@ class AttachmentRetrieverImpl implements AttachmentRetriever {
@Inject @Inject
AttachmentRetrieverImpl(MessagingManager messagingManager, AttachmentRetrieverImpl(MessagingManager messagingManager,
AttachmentDimensions dimensions, ImageHelper imageHelper) { AttachmentDimensions dimensions, ImageHelper imageHelper,
ImageSizeCalculator imageSizeCalculator) {
this.messagingManager = messagingManager; this.messagingManager = messagingManager;
this.imageHelper = imageHelper; this.imageHelper = imageHelper;
imageSizeCalculator = new ImageSizeCalculator(imageHelper); this.imageSizeCalculator = imageSizeCalculator;
defaultSize = dimensions.defaultSize; defaultSize = dimensions.defaultSize;
minWidth = dimensions.minWidth; minWidth = dimensions.minWidth;
maxWidth = dimensions.maxWidth; maxWidth = dimensions.maxWidth;
......
...@@ -2,11 +2,11 @@ package org.briarproject.briar.android.attachment; ...@@ -2,11 +2,11 @@ package org.briarproject.briar.android.attachment;
import org.briarproject.bramble.api.sync.MessageId; import org.briarproject.bramble.api.sync.MessageId;
import org.briarproject.bramble.test.BrambleMockTestCase; import org.briarproject.bramble.test.BrambleMockTestCase;
import org.briarproject.briar.android.attachment.ImageHelper.DecodeResult;
import org.briarproject.briar.api.messaging.Attachment; import org.briarproject.briar.api.messaging.Attachment;
import org.briarproject.briar.api.messaging.AttachmentHeader; import org.briarproject.briar.api.messaging.AttachmentHeader;
import org.briarproject.briar.api.messaging.MessagingManager; import org.briarproject.briar.api.messaging.MessagingManager;
import org.jmock.Expectations; import org.jmock.Expectations;
import org.jmock.lib.legacy.ClassImposteriser;
import org.junit.Test; import org.junit.Test;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
...@@ -24,14 +24,18 @@ public class AttachmentRetrieverTest extends BrambleMockTestCase { ...@@ -24,14 +24,18 @@ public class AttachmentRetrieverTest extends BrambleMockTestCase {
100, 50, 200, 75, 300 100, 50, 200, 75, 300
); );
private final MessageId msgId = new MessageId(getRandomId()); private final MessageId msgId = new MessageId(getRandomId());
private final MessagingManager messagingManager =
context.mock(MessagingManager.class);
private final ImageHelper imageHelper = context.mock(ImageHelper.class); private final ImageHelper imageHelper = context.mock(ImageHelper.class);
private final AttachmentRetriever retriever = new AttachmentRetrieverImpl( private final ImageSizeCalculator imageSizeCalculator;
messagingManager, private final AttachmentRetriever retriever;
dimensions,
imageHelper public AttachmentRetrieverTest() {
); context.setImposteriser(ClassImposteriser.INSTANCE);
MessagingManager messagingManager =
context.mock(MessagingManager.class);
imageSizeCalculator = context.mock(ImageSizeCalculator.class);
retriever = new AttachmentRetrieverImpl(messagingManager, dimensions,
imageHelper, imageSizeCalculator);
}
@Test @Test
public void testNoSize() { public void testNoSize() {
...@@ -69,8 +73,9 @@ public class AttachmentRetrieverTest extends BrambleMockTestCase { ...@@ -69,8 +73,9 @@ public class AttachmentRetrieverTest extends BrambleMockTestCase {
Attachment attachment = getAttachment(mimeType); Attachment attachment = getAttachment(mimeType);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(imageHelper).decodeStream(with(any(InputStream.class))); oneOf(imageSizeCalculator).getSize(with(any(InputStream.class)),
will(returnValue(new DecodeResult(160, 240, mimeType))); with(mimeType));
will(returnValue(new Size(160, 240, mimeType)));
oneOf(imageHelper).getExtensionFromMimeType(mimeType); oneOf(imageHelper).getExtensionFromMimeType(mimeType);
will(returnValue("jpg")); will(returnValue("jpg"));
}}); }});
...@@ -92,8 +97,9 @@ public class AttachmentRetrieverTest extends BrambleMockTestCase { ...@@ -92,8 +97,9 @@ public class AttachmentRetrieverTest extends BrambleMockTestCase {
Attachment attachment = getAttachment(mimeType); Attachment attachment = getAttachment(mimeType);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(imageHelper).decodeStream(with(any(InputStream.class))); oneOf(imageSizeCalculator).getSize(with(any(InputStream.class)),
will(returnValue(new DecodeResult(1728, 2592, mimeType))); with(mimeType));
will(returnValue(new Size(1728, 2592, mimeType)));
oneOf(imageHelper).getExtensionFromMimeType(mimeType); oneOf(imageHelper).getExtensionFromMimeType(mimeType);
will(returnValue("jpg")); will(returnValue("jpg"));
}}); }});
...@@ -108,11 +114,13 @@ public class AttachmentRetrieverTest extends BrambleMockTestCase { ...@@ -108,11 +114,13 @@ public class AttachmentRetrieverTest extends BrambleMockTestCase {
@Test @Test
public void testMalformedError() { public void testMalformedError() {
Attachment attachment = getAttachment("image/jpeg"); String mimeType = "image/jpeg";
Attachment attachment = getAttachment(mimeType);
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(imageHelper).decodeStream(with(any(InputStream.class))); oneOf(imageSizeCalculator).getSize(with(any(InputStream.class)),
will(returnValue(new DecodeResult(0, 0, ""))); with(mimeType));
will(returnValue(new Size()));
oneOf(imageHelper).getExtensionFromMimeType(""); oneOf(imageHelper).getExtensionFromMimeType("");
will(returnValue(null)); will(returnValue(null));
}}); }});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment