-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User a NetworkBitmapClient as a wrapper for Picasso
- Loading branch information
1 parent
0c13a5b
commit 662479a
Showing
9 changed files
with
116 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/artemzin/qualitymatters/models/NetworkBitmapClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.artemzin.qualitymatters.models; | ||
|
||
import android.widget.ImageView; | ||
|
||
public interface NetworkBitmapClient { | ||
void downloadInto(String url, ImageView imageView); | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/artemzin/qualitymatters/models/PicassoBitmapClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.artemzin.qualitymatters.models; | ||
|
||
import android.widget.ImageView; | ||
import com.squareup.picasso.Picasso; | ||
|
||
public class PicassoBitmapClient implements NetworkBitmapClient { | ||
|
||
private final Picasso picasso; | ||
|
||
public PicassoBitmapClient(final Picasso picasso) { | ||
this.picasso = picasso; | ||
} | ||
|
||
@Override | ||
public void downloadInto(String url, ImageView imageView) { | ||
picasso.load(url).fit().centerCrop().into(imageView); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/unitTests/java/com/artemzin/qualitymatters/models/PicassoBitmapClientTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.artemzin.qualitymatters.models; | ||
|
||
import android.support.annotation.NonNull; | ||
import android.widget.ImageView; | ||
|
||
import com.artemzin.qualitymatters.QualityMattersRobolectricUnitTestRunner; | ||
import com.squareup.picasso.Picasso; | ||
import com.squareup.picasso.RequestCreator; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(QualityMattersRobolectricUnitTestRunner.class) | ||
public class PicassoBitmapClientTest { | ||
|
||
@SuppressWarnings("NullableProblems") // Initialized in @Before. | ||
@NonNull | ||
private ImageView imageView; | ||
|
||
@SuppressWarnings("NullableProblems") // Initialized in @Before. | ||
@NonNull | ||
private Picasso picasso; | ||
|
||
private String url = "http://url.com"; | ||
|
||
@SuppressWarnings("NullableProblems") // Initialized in @Before. | ||
@NonNull | ||
private PicassoBitmapClient picassoBitmapClient; | ||
|
||
@Test | ||
public void downloadInto_should_load_then_fit_then_centerCrop() throws Exception { | ||
picasso = mock(Picasso.class); | ||
imageView = mock(ImageView.class); | ||
|
||
RequestCreator loadRequestCreator = mock(RequestCreator.class); | ||
RequestCreator fitRequestCreator = mock(RequestCreator.class); | ||
RequestCreator centerCropRequestCreator = mock(RequestCreator.class); | ||
|
||
when(picasso.load(url)).thenReturn(loadRequestCreator); | ||
when(loadRequestCreator.fit()).thenReturn(fitRequestCreator); | ||
when(fitRequestCreator.centerCrop()).thenReturn(centerCropRequestCreator); | ||
|
||
picassoBitmapClient = new PicassoBitmapClient(picasso); | ||
picassoBitmapClient.downloadInto(url, imageView); | ||
|
||
verify(picasso).load(url); | ||
verify(loadRequestCreator).fit(); | ||
verify(fitRequestCreator).centerCrop(); | ||
verify(centerCropRequestCreator).into(imageView); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters