提交 1b7c4295 编写于 作者: S Sam Judd

Remove deprecated ExpectedException calls.

上级 d2d5c4e4
......@@ -13,6 +13,7 @@ dependencies {
// build.gradle file.
testImplementation project(':glide')
testImplementation project(':annotation:compiler')
testImplementation "junit:junit:${JUNIT_VERSION}"
testImplementation "com.squareup:javapoet:${JAVAPOET_VERSION}"
testImplementation "com.google.auto.service:auto-service:${AUTO_SERVICE_VERSION}"
testImplementation "com.google.code.findbugs:jsr305:${JSR_305_VERSION}"
......
......@@ -2,40 +2,44 @@ package com.bumptech.glide.annotation.compiler;
import static com.google.testing.compile.CompilationSubject.assertThat;
import static com.google.testing.compile.Compiler.javac;
import static org.junit.Assert.assertThrows;
import com.google.testing.compile.Compilation;
import com.google.testing.compile.JavaFileObjects;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
* Tests AppGlideModules with invalid usages of the @Excludes annotation.
*/
// Ignore warnings since most methods use ExpectedException
// Ignore warnings since most methods use assertThrows
@SuppressWarnings("ResultOfMethodCallIgnored")
@RunWith(JUnit4.class)
public class InvalidAppGlideModuleWithExcludesTest {
@Rule public final ExpectedException expectedException = ExpectedException.none();
@Test
public void compilation_withMissingExcludedModuleClass_throws() {
expectedException.expect(RuntimeException.class);
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
JavaFileObjects.forSourceLines(
"AppModuleWithExcludes",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.Excludes;",
"import com.bumptech.glide.annotation.GlideModule;",
"import com.bumptech.glide.module.AppGlideModule;",
"import com.bumptech.glide.test.EmptyLibraryModule;",
"@GlideModule",
"@Excludes(EmptyLibraryModule.class)",
"public final class AppModuleWithExcludes extends AppGlideModule {}"));
assertThrows(
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
JavaFileObjects.forSourceLines(
"AppModuleWithExcludes",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.Excludes;",
"import com.bumptech.glide.annotation.GlideModule;",
"import com.bumptech.glide.module.AppGlideModule;",
"import com.bumptech.glide.test.EmptyLibraryModule;",
"@GlideModule",
"@Excludes(EmptyLibraryModule.class)",
"public final class AppModuleWithExcludes extends AppGlideModule {}"));
}
});
}
@Test
......
......@@ -8,21 +8,17 @@ import static org.junit.Assert.fail;
import com.google.common.truth.Truth;
import com.google.testing.compile.Compilation;
import com.google.testing.compile.JavaFileObjects;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
/**
* Checks assertions on {@link com.bumptech.glide.annotation.GlideExtension}s themselves.
*/
// Avoid warnings when using ExpectedException.
// Avoid warnings when asserting on exceptions.
@SuppressWarnings("ResultOfMethodCallIgnored")
@RunWith(JUnit4.class)
public class InvalidGlideExtensionTest {
@Rule public final ExpectedException expectedException = ExpectedException.none();
@Test
public void compilation_withPublicConstructor_fails() {
try {
......
......@@ -3,14 +3,14 @@ package com.bumptech.glide.annotation.compiler;
import static com.bumptech.glide.annotation.compiler.test.Util.emptyAppModule;
import static com.google.testing.compile.CompilationSubject.assertThat;
import static com.google.testing.compile.Compiler.javac;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
import com.google.common.truth.Truth;
import com.google.testing.compile.Compilation;
import com.google.testing.compile.JavaFileObjects;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
......@@ -18,30 +18,34 @@ import org.junit.runners.JUnit4;
* Checks assertions on {@link com.bumptech.glide.annotation.GlideExtension}s for methods annotated
* with {@link com.bumptech.glide.annotation.GlideOption}.
*/
// Ignore warnings since most methods use ExpectedException
// Ignore warnings since most methods use assertThrows.
@SuppressWarnings("ResultOfMethodCallIgnored")
@RunWith(JUnit4.class)
public class InvalidGlideOptionsExtensionTest {
@Rule public final ExpectedException expectedException = ExpectedException.none();
@Test
public void compilation_withAnnotatedNonStaticMethod_fails() {
expectedException.expect(RuntimeException.class);
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption",
" public void doSomething() {}",
"}"));
assertThrows(
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption",
" public void doSomething() {}",
"}"));
}
});
}
@Test
......@@ -118,44 +122,57 @@ public class InvalidGlideOptionsExtensionTest {
@Test
public void compilation_overridingOptionWithoutAnnotationType_fails() {
expectedException.expect(RuntimeException.class);
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"import com.bumptech.glide.request.RequestOptions;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption",
" public static void centerCrop(RequestOptions options) {}",
"}"));
assertThrows(
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"import com.bumptech.glide.request.RequestOptions;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption",
" public static void centerCrop(RequestOptions options) {}",
"}"));
}
});
}
@Test
public void compilation_withOverrideExtend_butNotOverridingMethod_fails() {
expectedException.expect(RuntimeException.class);
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"import com.bumptech.glide.request.RequestOptions;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption(override = GlideOption.OVERRIDE_EXTEND)",
" public static void something(RequestOptions options) {}",
"}"));
assertThrows(
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"import com.bumptech.glide.request.RequestOptions;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption(override = GlideOption.OVERRIDE_EXTEND)",
" public static void something(RequestOptions options) {}",
"}"));
}
});
}
@Test
......@@ -182,23 +199,29 @@ public class InvalidGlideOptionsExtensionTest {
@Test
public void compilation_withOverrideReplace_butNotOverridingMethod_fails() {
expectedException.expect(RuntimeException.class);
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"import com.bumptech.glide.request.RequestOptions;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption(override = GlideOption.OVERRIDE_REPLACE)",
" public static void something(RequestOptions options) {}",
"}"));
assertThrows(
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideOption;",
"import com.bumptech.glide.request.RequestOptions;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideOption(override = GlideOption.OVERRIDE_REPLACE)",
" public static void something(RequestOptions options) {}",
"}"));
}
});
}
@Test
......
......@@ -5,15 +5,15 @@ import static com.bumptech.glide.annotation.compiler.test.Util.emptyAppModule;
import static com.bumptech.glide.annotation.compiler.test.Util.subpackage;
import static com.google.testing.compile.CompilationSubject.assertThat;
import static com.google.testing.compile.Compiler.javac;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;
import com.google.common.truth.Truth;
import com.google.testing.compile.Compilation;
import com.google.testing.compile.JavaFileObjects;
import java.io.IOException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
......@@ -21,54 +21,64 @@ import org.junit.runners.JUnit4;
* Checks assertions on {@link com.bumptech.glide.annotation.GlideExtension}s for methods annotated
* with {@link com.bumptech.glide.annotation.GlideType}.
*/
// Ignore warnings since most methods use ExpectedException
// Ignore warnings since most methods use assertThrows.
@SuppressWarnings("ResultOfMethodCallIgnored")
@RunWith(JUnit4.class)
public class InvalidGlideTypeExtensionTest {
@Rule public final ExpectedException expectedException = ExpectedException.none();
@Test
public void compilation_withAnnotatedNonStaticMethod_fails() {
expectedException.expectMessage("@GlideType methods must be static");
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideType;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideType(Number.class)",
" public void doSomething() {}",
"}"));
assertThrows(
"@GlideType methods must be static",
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideType;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideType(Number.class)",
" public void doSomething() {}",
"}"));
}
});
}
@Test
public void compilation_withAnnotatedStaticMethod_withoutRequestBuilderArg_fails() {
expectedException
.expectMessage(
"@GlideType methods must take a RequestBuilder object as their first and only"
+ " parameter, but given multiple for:"
+ " com.bumptech.glide.test.Extension#doSomething()");
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideType;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideType(Number.class)",
" public static void doSomething() {}",
"}"));
assertThrows(
"@GlideType methods must take a RequestBuilder object as their first and only"
+ " parameter, but given multiple for:"
+ " com.bumptech.glide.test.Extension#doSomething()",
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideType;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideType(Number.class)",
" public static void doSomething() {}",
"}"));
}
});
}
@Test
......@@ -121,35 +131,40 @@ public class InvalidGlideTypeExtensionTest {
@Test
public void compilation_withAnnotatedStaticMethod_withRequestBuilderArgAndOtherArg_fails() {
expectedException
.expectMessage(
"@GlideType methods must take a RequestBuilder object as their first and only"
+ " parameter, but given multiple for:"
+ " com.bumptech.glide.test.Extension#type("
+ "com.bumptech.glide.RequestBuilder<java.lang.Number>,"
+ "java.lang.Object)");
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.RequestBuilder;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideType;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideType(Number.class)",
" public static void type(RequestBuilder<Number> builder, Object arg2) {}",
"}"));
assertThrows(
"@GlideType methods must take a RequestBuilder object as their first and only"
+ " parameter, but given multiple for:"
+ " com.bumptech.glide.test.Extension#type("
+ "com.bumptech.glide.RequestBuilder<java.lang.Number>,"
+ "java.lang.Object)",
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.RequestBuilder;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideType;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideType(Number.class)",
" public static void type(RequestBuilder<Number> builder, Object arg2) {}",
"}"));
}
});
}
@Test
public void compilation_withAnnotatedStaticMethod_overridingExistingType_fails()
throws IOException {
Compilation compilation =
final Compilation compilation =
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
......@@ -167,11 +182,17 @@ public class InvalidGlideTypeExtensionTest {
" @GlideType(Drawable.class)",
" public static void asDrawable(RequestBuilder<Drawable> builder) {}",
"}"));
expectedException
.expectMessage(
"error: method asDrawable() is already defined in class"
+ " com.bumptech.glide.test.GlideRequests");
compilation.generatedSourceFile(subpackage("GlideRequests"));
assertThrows(
"error: method asDrawable() is already defined in class"
+ " com.bumptech.glide.test.GlideRequests",
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
compilation.generatedSourceFile(subpackage("GlideRequests"));
}
});
}
@Test
......@@ -266,30 +287,36 @@ public class InvalidGlideTypeExtensionTest {
@Test
public void compilation_withAnnotatedStaticMethod_returningBuilder_andMultipleParams_fails() {
expectedException.expectMessage(
assertThrows(
"@GlideType methods must take a RequestBuilder object as their first and only parameter,"
+ " but given multiple for:"
+ " com.bumptech.glide.test.Extension#asNumber("
+ "com.bumptech.glide.RequestBuilder<java.lang.Number>,java.lang.Object)");
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.RequestBuilder;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideType;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideType(Number.class)",
" public static RequestBuilder<Number> asNumber(",
" RequestBuilder<Number> builder, Object arg1) {",
" return builder;",
" }",
"}"));
+ "com.bumptech.glide.RequestBuilder<java.lang.Number>,java.lang.Object)",
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(
emptyAppModule(),
JavaFileObjects.forSourceLines(
"Extension",
"package com.bumptech.glide.test;",
"import com.bumptech.glide.RequestBuilder;",
"import com.bumptech.glide.annotation.GlideExtension;",
"import com.bumptech.glide.annotation.GlideType;",
"@GlideExtension",
"public class Extension {",
" private Extension() {}",
" @GlideType(Number.class)",
" public static RequestBuilder<Number> asNumber(",
" RequestBuilder<Number> builder, Object arg1) {",
" return builder;",
" }",
"}"));
}
});
}
@Test
......
......@@ -2,6 +2,7 @@ package com.bumptech.glide.annotation.compiler;
import static com.google.testing.compile.CompilationSubject.assertThat;
import static com.google.testing.compile.Compiler.javac;
import static org.junit.Assert.assertThrows;
import com.bumptech.glide.annotation.compiler.test.RegenerateResourcesRule;
import com.bumptech.glide.annotation.compiler.test.Util;
......@@ -9,7 +10,7 @@ import com.google.testing.compile.Compilation;
import javax.tools.JavaFileObject;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
......@@ -23,16 +24,21 @@ public class MultipleAppGlideModuleTest {
private static final String SECOND_MODULE = "EmptyAppModule2.java";
@Rule public final RegenerateResourcesRule regenerateResourcesRule =
new RegenerateResourcesRule(getClass());
@Rule public final ExpectedException expectedException = ExpectedException.none();
// Throws.
@SuppressWarnings("ResultOfMethodCallIgnored")
@Test
public void compilation_withTwoAppModules_fails() {
expectedException.expect(RuntimeException.class);
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(forResource(FIRST_MODULE), forResource(SECOND_MODULE));
assertThrows(
RuntimeException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
javac()
.withProcessors(new GlideAnnotationProcessor())
.compile(forResource(FIRST_MODULE), forResource(SECOND_MODULE));
}
});
}
@Test
......
......@@ -14,7 +14,6 @@ import javax.tools.JavaFileObject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
......@@ -25,7 +24,6 @@ import org.junit.runners.JUnit4;
public class MultipleEmptyLibraryGlideModuleTest {
@Rule public final RegenerateResourcesRule regenerateResourcesRule =
new RegenerateResourcesRule(getClass());
@Rule public final ExpectedException expectedException = ExpectedException.none();
private Compilation compilation;
@Before
......
......@@ -17,7 +17,6 @@ import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
......@@ -27,7 +26,6 @@ import org.junit.runner.RunWith;
@RegressionTest
public class CenterInsideRegressionTest {
@Rule public final TestName testName = new TestName();
@Rule public final ExpectedException expectedException = ExpectedException.none();
@Rule public final TearDownGlide tearDownGlide = new TearDownGlide();
private BitmapRegressionTester bitmapRegressionTester;
private Context context;
......
......@@ -17,7 +17,6 @@ import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
......@@ -27,7 +26,6 @@ import org.junit.runner.RunWith;
@RegressionTest
public class CircleCropRegressionTest {
@Rule public final TestName testName = new TestName();
@Rule public final ExpectedException expectedException = ExpectedException.none();
@Rule public final TearDownGlide tearDownGlide = new TearDownGlide();
private BitmapRegressionTester bitmapRegressionTester;
private Context context;
......
package com.bumptech.glide;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
......@@ -22,15 +23,12 @@ import com.bumptech.glide.test.GlideApp;
import java.util.concurrent.ExecutionException;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class DrawableTransformationTest {
@Rule public final ExpectedException expectedException = ExpectedException.none();
private Context context;
@Before
......@@ -117,15 +115,21 @@ public class DrawableTransformationTest {
@Test
public void load_withColorDrawable_sizeOriginal_requiredTransform_fails()
throws ExecutionException, InterruptedException {
Drawable colorDrawable = new ColorDrawable(Color.RED);
expectedException.expect(ExecutionException.class);
Glide.with(context)
.load(colorDrawable)
.apply(new RequestOptions()
.centerCrop())
.submit()
.get();
final Drawable colorDrawable = new ColorDrawable(Color.RED);
assertThrows(
ExecutionException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
Glide.with(context)
.load(colorDrawable)
.apply(new RequestOptions()
.centerCrop())
.submit()
.get();
}
});
}
@Test
......
package com.bumptech.glide;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import android.content.Context;
import android.graphics.Bitmap;
......@@ -17,7 +18,7 @@ import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
......@@ -27,7 +28,6 @@ import org.junit.runner.RunWith;
@RegressionTest
public class FitCenterRegressionTest {
@Rule public final TestName testName = new TestName();
@Rule public final ExpectedException expectedException = ExpectedException.none();
@Rule public final TearDownGlide tearDownGlide = new TearDownGlide();
private BitmapRegressionTester bitmapRegressionTester;
private Context context;
......@@ -108,16 +108,23 @@ public class FitCenterRegressionTest {
public void fitCenter_withHugeRectangle_throwsOOM()
throws ExecutionException, InterruptedException {
float multiplier = Integer.MAX_VALUE / (canonical.getWidth() * canonical.getHeight() * 2);
int overrideWidth = (int) multiplier * canonical.getWidth();
int overrideHeight = (int) multiplier * canonical.getHeight();
expectedException.expect(ExecutionException.class);
GlideApp
.with(context)
.asBitmap()
.load(canonical.getBitmap())
.fitCenter()
.override(overrideWidth, overrideHeight)
.submit()
.get();
final int overrideWidth = (int) multiplier * canonical.getWidth();
final int overrideHeight = (int) multiplier * canonical.getHeight();
assertThrows(
ExecutionException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
GlideApp
.with(context)
.asBitmap()
.load(canonical.getBitmap())
.fitCenter()
.override(overrideWidth, overrideHeight)
.submit()
.get();
}
});
}
}
......@@ -3,6 +3,7 @@ package com.bumptech.glide;
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
import static com.bumptech.glide.request.RequestOptions.centerCropTransform;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import android.content.ContentResolver;
import android.content.Context;
......@@ -27,7 +28,7 @@ import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
......@@ -36,7 +37,6 @@ import org.mockito.MockitoAnnotations;
public class NonBitmapDrawableResourcesTest {
@Rule public final TestName testName = new TestName();
@Rule public final TearDownGlide tearDownGlide = new TearDownGlide();
@Rule public final ExpectedException expectedException = ExpectedException.none();
private Context context;
......@@ -123,12 +123,19 @@ public class NonBitmapDrawableResourcesTest {
@Test
public void load_withShapeDrawableResourceId_asDrawable_withTransformation_sizeOriginal_fails()
throws ExecutionException, InterruptedException {
expectedException.expect(ExecutionException.class);
Glide.with(context)
.load(ResourceIds.drawable.shape_drawable)
.apply(centerCropTransform())
.submit()
.get();
assertThrows(
ExecutionException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
Glide.with(context)
.load(ResourceIds.drawable.shape_drawable)
.apply(centerCropTransform())
.submit()
.get();
}
});
}
@Test
......@@ -147,12 +154,18 @@ public class NonBitmapDrawableResourcesTest {
@Test
public void load_withShapeDrawableResourceId_asBitmap_withSizeOriginal_fails()
throws ExecutionException, InterruptedException {
expectedException.expect(ExecutionException.class);
Glide.with(context)
.asBitmap()
.load(ResourceIds.drawable.shape_drawable)
.submit()
.get();
assertThrows(
ExecutionException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
Glide.with(context)
.asBitmap()
.load(ResourceIds.drawable.shape_drawable)
.submit()
.get();
}
});
}
@Test
......
package com.bumptech.glide.load.engine;
import static org.junit.Assert.assertThrows;
import android.support.annotation.NonNull;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.load.Option;
......@@ -12,9 +14,8 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
......@@ -24,7 +25,6 @@ import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 18)
public class EngineKeyTest {
@Rule public final ExpectedException expectedException = ExpectedException.none();
@Mock private Transformation<Object> transformation;
@Before
......@@ -35,7 +35,7 @@ public class EngineKeyTest {
@Test
public void updateDiskCacheKey_throwsException() throws NoSuchAlgorithmException {
// If this test fails, update testEqualsAndHashcode to use KeyTester including regression tests.
EngineKey key = new EngineKey(
final EngineKey key = new EngineKey(
"id",
new ObjectKey("signature"),
100,
......@@ -44,8 +44,14 @@ public class EngineKeyTest {
Object.class,
Object.class,
new Options());
expectedException.expect(UnsupportedOperationException.class);
key.updateDiskCacheKey(MessageDigest.getInstance("SHA-1"));
assertThrows(
UnsupportedOperationException.class,
new ThrowingRunnable() {
@Override
public void run() throws NoSuchAlgorithmException {
key.updateDiskCacheKey(MessageDigest.getInstance("SHA-1"));
}
});
}
@Test
......
package com.bumptech.glide.load.model;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
......@@ -13,9 +14,8 @@ import com.bumptech.glide.util.pool.FactoryPools;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
......@@ -28,8 +28,6 @@ import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(manifest = Config.NONE, sdk = 18)
public class MultiModelLoaderFactoryTest {
@Rule public final ExpectedException exception = ExpectedException.none();
@Mock private ModelLoaderFactory<String, String> firstFactory;
@Mock private ModelLoader<String, String> firstModelLoader;
@Mock private MultiModelLoaderFactory.Factory multiModelLoaderFactory;
......@@ -183,16 +181,28 @@ public class MultiModelLoaderFactoryTest {
public void testBuild_withModelAndDataClasses_excludesModelLoadersForOtherDataClasses() {
multiFactory.append(String.class, String.class, firstFactory);
exception.expect(NoModelLoaderAvailableException.class);
multiFactory.build(String.class, Integer.class);
assertThrows(
NoModelLoaderAvailableException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
multiFactory.build(String.class, Integer.class);
}
});
}
@Test
public void testBuild_withModelAndDataClasses_excludesModelLoadersForOtherModelClasses() {
multiFactory.append(String.class, String.class, firstFactory);
exception.expect(NoModelLoaderAvailableException.class);
multiFactory.build(Integer.class, String.class);
assertThrows(
NoModelLoaderAvailableException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
multiFactory.build(Integer.class, String.class);
}
});
}
@Test
......@@ -212,15 +222,28 @@ public class MultiModelLoaderFactoryTest {
@Test
public void testBuild_withModelAndDataClass_doesNotMatchSubclassesOfModelClass() {
appendFactoryFor(String.class, Object.class);
exception.expect(NoModelLoaderAvailableException.class);
multiFactory.build(Object.class, Object.class);
assertThrows(
NoModelLoaderAvailableException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
multiFactory.build(Object.class, Object.class);
}
});
}
@Test
public void testBuild_withModelAndDataClass_doesNotMatchSubclassesOfDataClass() {
appendFactoryFor(Object.class, String.class);
exception.expect(NoModelLoaderAvailableException.class);
multiFactory.build(Object.class, Object.class);
assertThrows(
NoModelLoaderAvailableException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
multiFactory.build(Object.class, Object.class);
}
});
}
@Test
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册