diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-07-15 02:01:24 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-07-15 02:01:24 +0000 |
commit | 58c8f7e340e7fde3cdaf83b975011a367c8d22c5 (patch) | |
tree | 0f4d08540c8e5fa16bcd0c99cd413fe815560e4b /base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommonTest.java | |
parent | b4233fd961752b80d42ae68e8b42acfb3e99be57 (diff) | |
parent | 0d51dc717edd4d97116b47bc156e83b8fa193d3d (diff) | |
download | libchrome-android12-mainline-captiveportallogin-release.tar.gz |
Snap for 7550930 from 0d51dc717edd4d97116b47bc156e83b8fa193d3d to mainline-captiveportallogin-releaseandroid-mainline-12.0.0_r6android-mainline-12.0.0_r23android12-mainline-captiveportallogin-release
Change-Id: I03317ab8469a70fb3b5bf17c4182639d8a76a31d
Diffstat (limited to 'base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommonTest.java')
-rw-r--r-- | base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommonTest.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommonTest.java b/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommonTest.java new file mode 100644 index 0000000000..6d854c57e6 --- /dev/null +++ b/base/test/android/junit/src/org/chromium/base/test/params/ParameterizedRunnerDelegateCommonTest.java @@ -0,0 +1,77 @@ +// Copyright 2018 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.base.test.params; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; +import org.junit.runners.model.TestClass; + +import org.chromium.base.test.params.ParameterizedRunner.ParameterizedTestInstantiationException; + +import java.util.Collections; + +@RunWith(BlockJUnit4ClassRunner.class) +public class ParameterizedRunnerDelegateCommonTest { + /** + * Create a test object using the list of class parameter set + * + * @param testClass the {@link TestClass} object for current test class + * @param classParameterSet the parameter set needed for the test class constructor + */ + private static Object createTest(TestClass testClass, ParameterSet classParameterSet) + throws ParameterizedTestInstantiationException { + return new ParameterizedRunnerDelegateCommon( + testClass, classParameterSet, Collections.emptyList()) + .createTest(); + } + + static class BadTestClassWithMoreThanOneConstructor { + public BadTestClassWithMoreThanOneConstructor() {} + @SuppressWarnings("unused") + public BadTestClassWithMoreThanOneConstructor(String argument) {} + } + + static class BadTestClassWithTwoArgumentConstructor { + @SuppressWarnings("unused") + public BadTestClassWithTwoArgumentConstructor(int a, int b) {} + } + + static abstract class BadTestClassAbstract { + public BadTestClassAbstract() {} + } + + static class BadTestClassConstructorThrows { + public BadTestClassConstructorThrows() { + throw new RuntimeException(); + } + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateTestWithMoreThanOneConstructor() throws Throwable { + TestClass testClass = new TestClass(BadTestClassWithMoreThanOneConstructor.class); + createTest(testClass, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateTestWithIncorrectArguments() throws Throwable { + TestClass testClass = new TestClass(BadTestClassWithTwoArgumentConstructor.class); + ParameterSet pSet = new ParameterSet().value(1, 2, 3); + createTest(testClass, pSet); + } + + @Test(expected = ParameterizedTestInstantiationException.class) + public void testCreateTestWithAbstractClass() throws ParameterizedTestInstantiationException { + TestClass testClass = new TestClass(BadTestClassAbstract.class); + createTest(testClass, null); + } + + @Test(expected = ParameterizedTestInstantiationException.class) + public void testCreateTestWithThrowingConstructor() + throws ParameterizedTestInstantiationException { + TestClass testClass = new TestClass(BadTestClassConstructorThrows.class); + createTest(testClass, null); + } +} |