提交 29438d5d 编写于 作者: S Sam Judd

Add an empty constructor for SimpleTarget.

Fixes #170.
上级 f08ab536
package com.bumptech.glide.request.target;
import com.bumptech.glide.request.animation.GlideAnimation;
import org.junit.Test;
import static org.mockito.Mockito.mock;
public class SimpleTargetTest {
@Test(expected = IllegalArgumentException.class)
public void testThrowsIfGivenWidthIsLessThanZero() {
new SimpleTarget<Object>(-1, 1) {
@Override
public void onResourceReady(Object resource, GlideAnimation<Object> glideAnimation) {
public void testThrowsOnGetSizeIfGivenWidthIsLessThanZero() {
getTarget(-1, 1).getSize(mock(SizeReadyCallback.class));
}
}
};
@Test(expected = IllegalArgumentException.class)
public void testThrowsOnGetSizeIfGivenWidthIsEqualToZero() {
getTarget(0, 1).getSize(mock(SizeReadyCallback.class));
}
@Test(expected = IllegalArgumentException.class)
public void testThrowsIfGivenWidthIsEqualToZero() {
new SimpleTarget<Object>(0, 1) {
public void testThrowsOnGetSizeIfGivenHeightIsLessThanZero() {
getTarget(1, -1).getSize(mock(SizeReadyCallback.class));
}
@Override
public void onResourceReady(Object resource, GlideAnimation<Object> glideAnimation) {
@Test(expected = IllegalArgumentException.class)
public void testThrowsOnGetSizeIfGivenHeightIsEqualToZero() {
getTarget(1, 0).getSize(mock(SizeReadyCallback.class));
}
}
};
@Test
public void testCanBeConstructedWithoutDimensions() {
getTarget();
}
@Test(expected = IllegalArgumentException.class)
public void testThrowsIfGivenHeightIsLessThanZero() {
new SimpleTarget<Object>(1, -1) {
public void testThrowsOnGetSizeIfConstructedWithoutDimensions() {
getTarget().getSize(mock(SizeReadyCallback.class));
}
private SimpleTarget<Object> getTarget() {
return new SimpleTarget<Object>() {
@Override
public void onResourceReady(Object resource, GlideAnimation<Object> glideAnimation) {
public void onResourceReady(Object resource, GlideAnimation<? super Object> glideAnimation) {
// Do nothing.
}
};
}
@Test(expected = IllegalArgumentException.class)
public void testThrowsIfGivenHeightIsEqualToZero() {
new SimpleTarget<Object>(1, 0) {
private SimpleTarget<Object> getTarget(int width, int height) {
return new SimpleTarget<Object>(width, height) {
@Override
public void onResourceReady(Object resource, GlideAnimation<Object> glideAnimation) {
public void onResourceReady(Object resource, GlideAnimation<? super Object> glideAnimation) {
// Do nothing.
}
};
}
......
......@@ -27,6 +27,20 @@ public abstract class SimpleTarget<Z> extends BaseTarget<Z> {
private final int width;
private final int height;
/**
* Constructor for the target that assumes you will have called
* {@link com.bumptech.glide.GenericRequestBuilder#override(int, int)} on the request builder this target is given
* to.
*
* <p>
* Requests that load into this target will throw an {@link java.lang.IllegalArgumentException} if
* {@link com.bumptech.glide.GenericRequestBuilder#override(int, int)} was not called on the request builder.
* </p>
*/
public SimpleTarget() {
this(-1, -1);
}
/**
* Constructor for the target that takes the desired dimensions of the decoded and/or transformed resource.
*
......@@ -34,10 +48,6 @@ public abstract class SimpleTarget<Z> extends BaseTarget<Z> {
* @param height The desired height of the resource.
*/
public SimpleTarget(int width, int height) {
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("Width and height must both be > 0, but given width: " + width + " and"
+ " height: " + height);
}
this.width = width;
this.height = height;
}
......@@ -49,6 +59,10 @@ public abstract class SimpleTarget<Z> extends BaseTarget<Z> {
*/
@Override
public final void getSize(SizeReadyCallback cb) {
if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("Width and height must both be > 0, but given width: " + width + " and"
+ " height: " + height + ", either provide dimensions in the constructor or call override()");
}
cb.onSizeReady(width, height);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册