forked from rallat/ImageLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from luigi-agosti/master
improve test coverage partially fixing issue #25
- Loading branch information
Showing
12 changed files
with
408 additions
and
15 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
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
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
7 changes: 7 additions & 0 deletions
7
core/src/test/java/com/novoda/imageloader/core/file/util/FileUtilTest.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.novoda.imageloader.core.file.util; | ||
|
||
public class FileUtilTest { | ||
|
||
|
||
|
||
} |
81 changes: 81 additions & 0 deletions
81
core/src/test/java/com/novoda/imageloader/core/model/ImageTagFactoryTest.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,81 @@ | ||
package com.novoda.imageloader.core.model; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static org.mockito.Mockito.*; | ||
|
||
import android.content.Context; | ||
import android.view.Display; | ||
import android.view.WindowManager; | ||
|
||
public class ImageTagFactoryTest { | ||
|
||
private ImageTagFactory imageTagFactory; | ||
private int height = 12; | ||
private int width = 9; | ||
private int defaultResourceId = 1; | ||
private String url = "google.com"; | ||
|
||
@Before | ||
public void beforeEachTest() { | ||
imageTagFactory = new ImageTagFactory(9, 12, 1); | ||
} | ||
|
||
@Test | ||
public void shouldSetNormalPropertiesOnTheImageTag() { | ||
ImageTag imageTag = imageTagFactory.build(url); | ||
|
||
assertEquals(defaultResourceId, imageTag.getLoadingResourceId()); | ||
assertEquals(defaultResourceId, imageTag.getNotFoundResourceId()); | ||
assertEquals(height, imageTag.getHeight()); | ||
assertEquals(width, imageTag.getWidth()); | ||
assertEquals(url, imageTag.getUrl()); | ||
} | ||
|
||
@Test | ||
public void shouldSetPreviewProperties() { | ||
int previewHeight = 1; | ||
int previewWidth = 2; | ||
imageTagFactory.usePreviewImage(previewWidth, previewHeight, true); | ||
ImageTag imageTag = imageTagFactory.build(url); | ||
|
||
assertEquals(previewHeight, imageTag.getPreviewHeight()); | ||
assertEquals(previewWidth, imageTag.getPreviewWidth()); | ||
} | ||
|
||
@Test | ||
public void shouldUseTheSameUrlForPreview() { | ||
imageTagFactory.usePreviewImage(1, 1, true); | ||
ImageTag imageTag = imageTagFactory.build(url); | ||
|
||
assertEquals(url, imageTag.getPreviewUrl()); | ||
} | ||
|
||
@Test | ||
public void shouldNotUseTheSameUrlForPreview() { | ||
imageTagFactory.usePreviewImage(1, 1, false); | ||
ImageTag imageTag = imageTagFactory.build(url); | ||
|
||
assertNull(imageTag.getPreviewUrl()); | ||
} | ||
|
||
@Test | ||
public void shouldUseDisplaySizes() { | ||
final Display display = mock(Display.class); | ||
when(display.getHeight()).thenReturn(21); | ||
when(display.getWidth()).thenReturn(12); | ||
imageTagFactory = new ImageTagFactory(null, 1) { | ||
@Override | ||
protected Display prepareDisplay(Context context) { | ||
return display; | ||
} | ||
}; | ||
ImageTag imageTag = imageTagFactory.build(url); | ||
assertEquals(21, imageTag.getHeight()); | ||
assertEquals(12, imageTag.getWidth()); | ||
} | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
core/src/test/java/com/novoda/imageloader/core/model/ImageWrapperTest.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,72 @@ | ||
package com.novoda.imageloader.core.model; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.Mockito.*; | ||
|
||
import android.widget.ImageView; | ||
|
||
|
||
public class ImageWrapperTest { | ||
|
||
private ImageWrapper imageWrapper; | ||
private ImageView imageView; | ||
private ImageTag imageTag; | ||
|
||
@Before | ||
public void beforeEachTest() { | ||
imageView = mock(ImageView.class); | ||
imageTag = mock(ImageTag.class); | ||
|
||
} | ||
|
||
@Test | ||
public void shouldNotFailIfImageTagIsNull() { | ||
imageWrapper = new ImageWrapper(imageView); | ||
} | ||
|
||
@Test | ||
public void shouldSetLoadingResourceId() { | ||
when(imageTag.getLoadingResourceId()).thenReturn(1); | ||
when(imageView.getTag()).thenReturn(imageTag); | ||
|
||
imageWrapper = new ImageWrapper(imageView); | ||
assertEquals(1, imageWrapper.getLoadingResourceId()); | ||
} | ||
|
||
@Test | ||
public void shouldSetNotFoundResourceIdIfDefined() { | ||
when(imageTag.getNotFoundResourceId()).thenReturn(2); | ||
when(imageView.getTag()).thenReturn(imageTag); | ||
|
||
imageWrapper = new ImageWrapper(imageView); | ||
assertEquals(2, imageWrapper.getNotFoundResourceId()); | ||
} | ||
|
||
@Test | ||
public void shouldReturnTrueIfCurrentUrlHasChanged() { | ||
when(imageTag.getUrl()).thenReturn("url1"); | ||
when(imageView.getTag()).thenReturn(imageTag); | ||
|
||
imageWrapper = new ImageWrapper(imageView); | ||
when(imageTag.getUrl()).thenReturn("url2"); | ||
|
||
assertTrue(imageWrapper.isUrlChanged()); | ||
} | ||
|
||
@Test | ||
public void shouldReturnFalseIfCurrentUrlHasNotChanged() { | ||
when(imageTag.getUrl()).thenReturn("url1"); | ||
when(imageView.getTag()).thenReturn(imageTag); | ||
|
||
imageWrapper = new ImageWrapper(imageView); | ||
when(imageTag.getUrl()).thenReturn("url1"); | ||
|
||
assertFalse(imageWrapper.isUrlChanged()); | ||
} | ||
|
||
} |
Oops, something went wrong.