();
38 | }
39 |
40 | /**
41 | * Creates a resizable {@code ArrayList} instance containing the given
42 | * elements.
43 | *
44 | * Note: due to a bug in javac 1.5.0_06, we cannot support the
45 | * following:
46 | *
47 | *
{@code List list = Lists.newArrayList(sub1, sub2);}
48 | *
49 | *
where {@code sub1} and {@code sub2} are references to subtypes of
50 | * {@code Base}, not of {@code Base} itself. To get around this, you must
51 | * use:
52 | *
53 | *
{@code List list = Lists.newArrayList(sub1, sub2);}
54 | *
55 | * @param elements the elements that the list should contain, in order
56 | * @return a newly-created {@code ArrayList} containing those elements
57 | */
58 | public static ArrayList newArrayList(E... elements) {
59 | int capacity = (elements.length * 110) / 100 + 5;
60 | ArrayList list = new ArrayList(capacity);
61 | Collections.addAll(list, elements);
62 | return list;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/google/android/collect/Maps.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2007 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.google.android.collect;
18 |
19 | import java.util.HashMap;
20 |
21 | /**
22 | * Provides static methods for creating mutable {@code Maps} instances easily.
23 | */
24 | public class Maps {
25 | /**
26 | * Creates a {@code HashMap} instance.
27 | *
28 | * @return a newly-created, initially-empty {@code HashMap}
29 | */
30 | public static HashMap newHashMap() {
31 | return new HashMap();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/ActivityTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.app.Activity;
19 | import android.test.ActivityTestCase;
20 |
21 | class ActivityTester extends ActivityTestCase {
22 |
23 | public ActivityTester(Object owner) {
24 | Infrastructure.setInstrumentationToInstrumentationTest(this);
25 | Infrastructure.setPerformanceWriterIfPerformanceCollectorTestCase(owner);
26 | }
27 |
28 | /* (non-Javadoc)
29 | * @see junit.framework.TestCase#setUp()
30 | */
31 | @Override
32 | public void setUp() throws Exception {
33 | super.setUp();
34 | }
35 |
36 | /* (non-Javadoc)
37 | * @see android.test.InstrumentationTestCase#tearDown()
38 | */
39 | @Override
40 | public void tearDown() throws Exception {
41 | super.tearDown();
42 | }
43 |
44 | /* (non-Javadoc)
45 | * @see android.test.ActivityTestCase#getActivity()
46 | */
47 | @Override
48 | public Activity getActivity() {
49 | return super.getActivity();
50 | }
51 |
52 | /* (non-Javadoc)
53 | * @see android.test.ActivityTestCase#scrubClass(java.lang.Class)
54 | */
55 | @Override
56 | public void scrubClass(Class> testCaseClass) throws IllegalAccessException {
57 | super.scrubClass(testCaseClass);
58 | }
59 |
60 | /* (non-Javadoc)
61 | * @see android.test.ActivityTestCase#setActivity(android.app.Activity)
62 | */
63 | @Override
64 | public void setActivity(Activity testActivity) {
65 | super.setActivity(testActivity);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/AndroidTestCaseInjector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.content.Context;
19 | import android.os.Build;
20 | import android.test.AndroidTestCase;
21 |
22 | abstract class AndroidTestCaseInjector {
23 |
24 | abstract void setTestContext(AndroidTestCase test,
25 | Context context);
26 |
27 | abstract Context getTestContext(AndroidTestCase test);
28 |
29 | private static final AndroidTestCaseInjector sInjector = ensureInstance();
30 |
31 | private static final AndroidTestCaseInjector ensureInstance() {
32 | @SuppressWarnings("deprecation")
33 | final int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
34 | if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
35 | return new CupcakeAndroidTestCaseInjector();
36 | } else {
37 | return new EclairAndroidTestCaseInjector();
38 | }
39 | }
40 |
41 | static AndroidTestCaseInjector getInstance() {
42 | return sInjector;
43 | }
44 |
45 | private static final class CupcakeAndroidTestCaseInjector extends AndroidTestCaseInjector {
46 |
47 | @Override
48 | void setTestContext(AndroidTestCase test,
49 | Context context) {
50 | // noop.
51 | }
52 |
53 | @Override
54 | Context getTestContext(AndroidTestCase test) {
55 | return null;
56 | }
57 | }
58 |
59 | private static final class EclairAndroidTestCaseInjector extends AndroidTestCaseInjector {
60 |
61 | @Override
62 | void setTestContext(AndroidTestCase test,
63 | Context context) {
64 | test.setTestContext(context);
65 | }
66 |
67 | @Override
68 | Context getTestContext(AndroidTestCase test) {
69 | return test.getTestContext();
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/AndroidTestRunner.java:
--------------------------------------------------------------------------------
1 | package com.uphyca.testing;
2 |
3 | import org.junit.runners.BlockJUnit4ClassRunner;
4 | import org.junit.runners.model.InitializationError;
5 |
6 | public class AndroidTestRunner extends BlockJUnit4ClassRunner {
7 |
8 | public AndroidTestRunner(Class> klass) throws InitializationError {
9 | super(klass);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/AndroidTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.test.AndroidTestCase;
19 |
20 | class AndroidTester extends AndroidTestCase {
21 |
22 | public AndroidTester(Object owner) {
23 | Infrastructure.setContextToAndroidTestCase(this);
24 | Infrastructure.setPerformanceWriterIfPerformanceCollectorTestCase(owner);
25 | }
26 |
27 | /* (non-Javadoc)
28 | * @see android.test.AndroidTestCase#setUp()
29 | */
30 | @Override
31 | public void setUp() throws Exception {
32 | super.setUp();
33 | }
34 |
35 | /* (non-Javadoc)
36 | * @see android.test.AndroidTestCase#tearDown()
37 | */
38 | @Override
39 | public void tearDown() throws Exception {
40 | super.tearDown();
41 | }
42 |
43 | /* (non-Javadoc)
44 | * @see android.test.AndroidTestCase#scrubClass(java.lang.Class)
45 | */
46 | @Override
47 | public void scrubClass(Class> testCaseClass) throws IllegalAccessException {
48 | super.scrubClass(testCaseClass);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/ApplicationTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.app.Application;
19 | import android.test.ApplicationTestCase;
20 |
21 | class ApplicationTester extends ApplicationTestCase {
22 |
23 | public ApplicationTester(Object owner,
24 | Class applicationClass) {
25 | super(applicationClass);
26 | Infrastructure.setContextToAndroidTestCase(this);
27 | Infrastructure.setPerformanceWriterIfPerformanceCollectorTestCase(owner);
28 | }
29 |
30 | /* (non-Javadoc)
31 | * @see android.test.ApplicationTestCase#setUp()
32 | */
33 | @Override
34 | public void setUp() throws Exception {
35 | super.setUp();
36 | }
37 |
38 | /* (non-Javadoc)
39 | * @see android.test.ApplicationTestCase#tearDown()
40 | */
41 | @Override
42 | public void tearDown() throws Exception {
43 | super.tearDown();
44 | }
45 |
46 | /* (non-Javadoc)
47 | * @see android.test.AndroidTestCase#scrubClass(java.lang.Class)
48 | */
49 | @Override
50 | public void scrubClass(Class> testCaseClass) throws IllegalAccessException {
51 | super.scrubClass(testCaseClass);
52 | }
53 |
54 | public void doCreateApplication() {
55 | super.createApplication();
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/InjectInstrumentationRule.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import org.junit.rules.TestRule;
19 | import org.junit.runner.Description;
20 | import org.junit.runners.model.Statement;
21 |
22 | //TODO Use this class instead of Tester's initilization code.
23 | class InjectInstrumentationRule implements TestRule {
24 |
25 | private InstrumentationSupport _test;
26 |
27 | public InjectInstrumentationRule(InstrumentationSupport test) {
28 | _test = test;
29 | }
30 |
31 | @Override
32 | public Statement apply(final Statement statement,
33 | final Description description) {
34 | return new Statement() {
35 | @Override
36 | public void evaluate() throws Throwable {
37 | _test.injectInstrumentation(Infrastructure.getInstrumentation());
38 | statement.evaluate();
39 | }
40 | };
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/InstrumentationSupport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.app.Instrumentation;
19 |
20 | public interface InstrumentationSupport {
21 |
22 | /**
23 | * Injects instrumentation into this test case. This method is
24 | * called by the test runner during test setup.
25 | *
26 | * @param instrumentation the instrumentation to use with this instance
27 | */
28 | void injectInstrumentation(Instrumentation instrumentation);
29 |
30 |
31 | /**
32 | * Injects instrumentation into this test case. This method is
33 | * called by the test runner during test setup.
34 | *
35 | * @param instrumentation the instrumentation to use with this instance
36 | *
37 | * @deprecated Incorrect spelling,
38 | * use {@link #injectInstrumentation(android.app.Instrumentation)} instead.
39 | */
40 | @Deprecated
41 | void injectInsrumentation(Instrumentation instrumentation);
42 |
43 | /**
44 | * Inheritors can access the instrumentation using this.
45 | * @return instrumentation
46 | */
47 | public Instrumentation getInstrumentation();
48 | }
49 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/InstrumentationTestCaseInjector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.annotation.TargetApi;
19 | import android.app.Instrumentation;
20 | import android.os.Build;
21 | import android.test.InstrumentationTestCase;
22 |
23 | abstract class InstrumentationTestCaseInjector {
24 |
25 | abstract void injectInstrumentation(InstrumentationTestCase test,
26 | Instrumentation instrumentation);
27 |
28 | private static final InstrumentationTestCaseInjector sInjector = ensureInstance();
29 |
30 | private static final InstrumentationTestCaseInjector ensureInstance() {
31 | @SuppressWarnings("deprecation")
32 | final int sdkVersion = Integer.parseInt(Build.VERSION.SDK);
33 | if (sdkVersion < Build.VERSION_CODES.ECLAIR) {
34 | return new CupcakeInstrumentationInjector();
35 | } else {
36 | return new EclairInstrumentationInjector();
37 | }
38 | }
39 |
40 | static InstrumentationTestCaseInjector getInstance() {
41 | return sInjector;
42 | }
43 |
44 | private static final class CupcakeInstrumentationInjector extends InstrumentationTestCaseInjector {
45 |
46 | @SuppressWarnings("deprecation")
47 | @Override
48 | public void injectInstrumentation(InstrumentationTestCase test,
49 | Instrumentation instrumentation) {
50 | test.injectInsrumentation(instrumentation);
51 | }
52 | }
53 |
54 |
55 |
56 | private static final class EclairInstrumentationInjector extends InstrumentationTestCaseInjector {
57 |
58 | @TargetApi(5)
59 | @Override
60 | public void injectInstrumentation(InstrumentationTestCase test,
61 | Instrumentation instrumentation) {
62 | test.injectInstrumentation(instrumentation);
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/InstrumentationTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.test.InstrumentationTestCase;
19 |
20 | class InstrumentationTester extends InstrumentationTestCase {
21 |
22 | public InstrumentationTester(Object owner) {
23 | Infrastructure.setInstrumentationToInstrumentationTest(this);
24 | Infrastructure.setPerformanceWriterIfPerformanceCollectorTestCase(owner);
25 | }
26 |
27 | /* (non-Javadoc)
28 | * @see junit.framework.TestCase#setUp()
29 | */
30 | @Override
31 | public void setUp() throws Exception {
32 | super.setUp();
33 | }
34 |
35 | /* (non-Javadoc)
36 | * @see android.test.InstrumentationTestCase#tearDown()
37 | */
38 | @Override
39 | public void tearDown() throws Exception {
40 | super.tearDown();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/JUnit4TestClassAdaptingListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import junit.framework.JUnit4TestAdapterCache;
19 | import junit.framework.TestResult;
20 |
21 | import org.junit.runner.Description;
22 | import org.junit.runner.notification.Failure;
23 | import org.junit.runner.notification.RunListener;
24 |
25 | class JUnit4TestClassAdaptingListener extends RunListener {
26 |
27 | private TestResult _result;
28 | private JUnit4TestAdapterCache _cache;
29 |
30 | public JUnit4TestClassAdaptingListener(TestResult result,
31 | JUnit4TestAdapterCache cache) {
32 | this._result = result;
33 | this._cache = cache;
34 | }
35 |
36 | @Override
37 | public void testFailure(Failure failure) throws Exception {
38 | _result.addError(_cache.asTest(failure.getDescription()),
39 | failure.getException());
40 | }
41 |
42 | @Override
43 | public void testFinished(Description description) throws Exception {
44 | _result.endTest(_cache.asTest(description));
45 | }
46 |
47 | @Override
48 | public void testStarted(Description description) throws Exception {
49 | _result.startTest(_cache.asTest(description));
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/LoaderTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.annotation.TargetApi;
19 | import android.test.LoaderTestCase;
20 |
21 | @TargetApi(11)
22 | class LoaderTester extends LoaderTestCase {
23 |
24 | public LoaderTester(Object owner) {
25 | Infrastructure.setContextToAndroidTestCase(this);
26 | Infrastructure.setPerformanceWriterIfPerformanceCollectorTestCase(owner);
27 | }
28 |
29 | /* (non-Javadoc)
30 | * @see android.test.AndroidTestCase#setUp()
31 | */
32 | @Override
33 | public void setUp() throws Exception {
34 | super.setUp();
35 | }
36 |
37 | /* (non-Javadoc)
38 | * @see android.test.AndroidTestCase#tearDown()
39 | */
40 | @Override
41 | public void tearDown() throws Exception {
42 | super.tearDown();
43 | }
44 |
45 | /* (non-Javadoc)
46 | * @see android.test.AndroidTestCase#scrubClass(java.lang.Class)
47 | */
48 | @Override
49 | public void scrubClass(Class> testCaseClass) throws IllegalAccessException {
50 | super.scrubClass(testCaseClass);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/ProviderTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.content.ContentProvider;
19 | import android.test.ProviderTestCase;
20 |
21 | @Deprecated
22 | class ProviderTester extends ProviderTestCase {
23 |
24 | public ProviderTester(Object owner,
25 | Class providerClass,
26 | String providerAuthority) {
27 | super(providerClass, providerAuthority);
28 | Infrastructure.setInstrumentationToInstrumentationTest(this);
29 | Infrastructure.setPerformanceWriterIfPerformanceCollectorTestCase(owner);
30 | }
31 |
32 | /* (non-Javadoc)
33 | * @see android.test.ProviderTestCase#setUp()
34 | */
35 | @Override
36 | public void setUp() throws Exception {
37 | super.setUp();
38 | }
39 |
40 | /* (non-Javadoc)
41 | * @see android.test.ProviderTestCase#tearDown()
42 | */
43 | @Override
44 | public void tearDown() throws Exception {
45 | super.tearDown();
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/ProviderTester2.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.content.ContentProvider;
19 | import android.test.ProviderTestCase2;
20 |
21 | class ProviderTester2 extends ProviderTestCase2 {
22 |
23 | public ProviderTester2(Object owner,
24 | Class providerClass,
25 | String providerAuthority) {
26 | super(providerClass, providerAuthority);
27 | Infrastructure.setContextToAndroidTestCase(this);
28 | Infrastructure.setPerformanceWriterIfPerformanceCollectorTestCase(owner);
29 | }
30 |
31 | /* (non-Javadoc)
32 | * @see android.test.ProviderTestCase2#setUp()
33 | */
34 | @Override
35 | public void setUp() throws Exception {
36 | super.setUp();
37 | }
38 |
39 | /* (non-Javadoc)
40 | * @see android.test.ProviderTestCase2#tearDown()
41 | */
42 | @Override
43 | public void tearDown() throws Exception {
44 | super.tearDown();
45 | }
46 |
47 | /* (non-Javadoc)
48 | * @see android.test.AndroidTestCase#scrubClass(java.lang.Class)
49 | */
50 | @Override
51 | public void scrubClass(Class> testCaseClass) throws IllegalAccessException {
52 | super.scrubClass(testCaseClass);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/ServiceTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.app.Service;
19 | import android.content.Intent;
20 | import android.os.IBinder;
21 | import android.test.ServiceTestCase;
22 |
23 | class ServiceTester extends ServiceTestCase {
24 |
25 | public ServiceTester(Object owner,
26 | Class serviceClass) {
27 | super(serviceClass);
28 | Infrastructure.setContextToAndroidTestCase(this);
29 | Infrastructure.setPerformanceWriterIfPerformanceCollectorTestCase(owner);
30 | }
31 |
32 | /* (non-Javadoc)
33 | * @see android.test.ServiceTestCase#setUp()
34 | */
35 | @Override
36 | public void setUp() throws Exception {
37 | super.setUp();
38 | }
39 |
40 | /* (non-Javadoc)
41 | * @see android.test.ServiceTestCase#tearDown()
42 | */
43 | @Override
44 | public void tearDown() throws Exception {
45 | super.tearDown();
46 | }
47 |
48 | /* (non-Javadoc)
49 | * @see android.test.ServiceTestCase#bindService(android.content.Intent)
50 | */
51 | @Override
52 | public IBinder bindService(Intent intent) {
53 | return super.bindService(intent);
54 | }
55 |
56 | /* (non-Javadoc)
57 | * @see android.test.ServiceTestCase#setupService()
58 | */
59 | @Override
60 | public void setupService() {
61 | super.setupService();
62 | }
63 |
64 | /* (non-Javadoc)
65 | * @see android.test.ServiceTestCase#shutdownService()
66 | */
67 | @Override
68 | public void shutdownService() {
69 | super.shutdownService();
70 | }
71 |
72 | /* (non-Javadoc)
73 | * @see android.test.ServiceTestCase#startService(android.content.Intent)
74 | */
75 | @Override
76 | public void startService(Intent intent) {
77 | super.startService(intent);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/SingleLaunchActivityTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.app.Activity;
19 | import android.test.SingleLaunchActivityTestCase;
20 |
21 | class SingleLaunchActivityTester extends SingleLaunchActivityTestCase {
22 |
23 | public SingleLaunchActivityTester(Object owner,
24 | String pkg,
25 | Class activityClass) {
26 | super(pkg, activityClass);
27 | Infrastructure.setInstrumentationToInstrumentationTest(this);
28 | Infrastructure.setPerformanceWriterIfPerformanceCollectorTestCase(owner);
29 | }
30 |
31 | /* (non-Javadoc)
32 | * @see android.test.SingleLaunchActivityTestCase#setUp()
33 | */
34 | @Override
35 | public void setUp() throws Exception {
36 | super.setUp();
37 | }
38 |
39 | /* (non-Javadoc)
40 | * @see android.test.SingleLaunchActivityTestCase#tearDown()
41 | */
42 | @Override
43 | public void tearDown() throws Exception {
44 | super.tearDown();
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/SyncBaseInstrumentationTester.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 uPhyca Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing;
17 |
18 | import android.net.Uri;
19 | import android.test.SyncBaseInstrumentation;
20 |
21 | class SyncBaseInstrumentationTester extends SyncBaseInstrumentation {
22 |
23 | public SyncBaseInstrumentationTester(Object owner) {
24 | Infrastructure.setInstrumentationToInstrumentationTest(this);
25 | Infrastructure.setPerformanceWriterIfPerformanceCollectorTestCase(owner);
26 | }
27 |
28 | /* (non-Javadoc)
29 | * @see android.test.SyncBaseInstrumentation#setUp()
30 | */
31 | @Override
32 | public void setUp() throws Exception {
33 | super.setUp();
34 | }
35 |
36 | /* (non-Javadoc)
37 | * @see android.test.InstrumentationTestCase#tearDown()
38 | */
39 | @Override
40 | public void tearDown() throws Exception {
41 | super.tearDown();
42 | }
43 |
44 | /* (non-Javadoc)
45 | * @see android.test.SyncBaseInstrumentation#cancelSyncsandDisableAutoSync()
46 | */
47 | @Override
48 | public void cancelSyncsandDisableAutoSync() {
49 | super.cancelSyncsandDisableAutoSync();
50 | }
51 |
52 | /* (non-Javadoc)
53 | * @see android.test.SyncBaseInstrumentation#syncProvider(android.net.Uri, java.lang.String, java.lang.String)
54 | */
55 | @Override
56 | public void syncProvider(Uri uri,
57 | String accountName,
58 | String authority) throws Exception {
59 | super.syncProvider(uri,
60 | accountName,
61 | authority);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/android/JUnit4NoExecTestResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.uphyca.testing.android;
17 |
18 | import junit.framework.TestCase;
19 | import junit.framework.TestResult;
20 |
21 | /**
22 | * A benign test result that does no actually test execution, just runs
23 | * through the motions
24 | *
25 | * {@hide} Not needed for SDK.
26 | */
27 | public class JUnit4NoExecTestResult extends TestResult {
28 |
29 | /**
30 | * Override parent to just inform listeners of test,
31 | * and skip test execution.
32 | */
33 | @Override
34 | protected void run(final TestCase test) {
35 | startTest(test);
36 | endTest(test);
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/android/PackageInfoSources.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.uphyca.testing.android;
18 |
19 | /**
20 | * {@hide} Not needed for SDK.
21 | */
22 | public class PackageInfoSources {
23 |
24 | private static ClassPathPackageInfoSource classPathSource;
25 |
26 | private PackageInfoSources() {
27 | }
28 |
29 | public static ClassPathPackageInfoSource forClassPath(ClassLoader classLoader) {
30 | if (classPathSource == null) {
31 | classPathSource = new ClassPathPackageInfoSource();
32 | classPathSource.setClassLoader(classLoader);
33 | }
34 | return classPathSource;
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/android/SimpleCache.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.uphyca.testing.android;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 | abstract class SimpleCache {
23 | private Map map = new HashMap();
24 |
25 | protected abstract V load(K key);
26 |
27 | final V get(K key) {
28 | if (map.containsKey(key)) {
29 | return map.get(key);
30 | }
31 | V value = load(key);
32 | map.put(key, value);
33 | return value;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/android/suitebuilder/Filters.java:
--------------------------------------------------------------------------------
1 | package com.uphyca.testing.android.suitebuilder;
2 |
3 | import org.junit.runner.Description;
4 | import org.junit.runner.manipulation.Filter;
5 |
6 | /**
7 | * Filters.
8 | */
9 | abstract class Filters {
10 |
11 | public static Filter union(final Filter first, final Filter second) {
12 | if (first == second || first == Filter.ALL) {
13 | return first;
14 | }
15 | if (second == Filter.ALL) {
16 | return second;
17 | }
18 |
19 | return new Filter() {
20 | @Override
21 | public boolean shouldRun(Description description) {
22 | return first.shouldRun(description) || second.shouldRun(description);
23 | }
24 |
25 | @Override
26 | public String describe() {
27 | return first.describe() + " or " + second.describe();
28 | }
29 | };
30 | }
31 |
32 |
33 | /**
34 | * FIXME Ensure child descriptions
35 | * @param desiredDescription
36 | * @return
37 | */
38 | public static Filter matchSuiteDescription(final Description desiredDescription) {
39 | return new Filter() {
40 | @Override
41 | public boolean shouldRun(Description description) {
42 | if (description.isTest())
43 | return desiredDescription.getTestClass() == description.getTestClass();
44 |
45 | // explicitly check if any children want to run
46 | for (Description each : description.getChildren())
47 | if (shouldRun(each))
48 | return true;
49 | return false;
50 | }
51 |
52 | @Override
53 | public String describe() {
54 | return String.format("Suite %s", desiredDescription.getClassName());
55 | }
56 | };
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/android/suitebuilder/JUnit4AssignableFrom.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.uphyca.testing.android.suitebuilder;
18 |
19 | import org.junit.runner.Description;
20 |
21 | import com.android.internal.util.Predicate;
22 |
23 | /**
24 | * Modified version of android.test.suitebuilder.AssignableFrom.
25 | */
26 | class JUnit4AssignableFrom implements Predicate {
27 |
28 | private final Class> root;
29 |
30 | JUnit4AssignableFrom(Class> root) {
31 | this.root = root;
32 | }
33 |
34 | public boolean apply(Description description) {
35 | return root.isAssignableFrom(description.getTestClass());
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/android/suitebuilder/annotation/JUnit4HasAnnotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.uphyca.testing.android.suitebuilder.annotation;
18 |
19 | import static com.android.internal.util.Predicates.or;
20 |
21 | import java.lang.annotation.Annotation;
22 |
23 | import org.junit.runner.Description;
24 |
25 | import com.android.internal.util.Predicate;
26 |
27 | /**
28 | * Modified version of android.test.suitebuilder.annotation.HasAnnotation.
29 | *
30 | *
31 | * A predicate that checks to see if a {@link Description} has a specific annotation, either on the
32 | * method or on the containing class.
33 | *
34 | * {@hide} Not needed for 1.0 SDK.
35 | */
36 | public class JUnit4HasAnnotation implements Predicate {
37 |
38 | private Predicate hasMethodOrClassAnnotation;
39 |
40 | public JUnit4HasAnnotation(Class extends Annotation> annotationClass) {
41 | this.hasMethodOrClassAnnotation = or(
42 | new JUnit4HasMethodAnnotation(annotationClass),
43 | new JUnit4HasClassAnnotation(annotationClass));
44 | }
45 |
46 | public boolean apply(Description description) {
47 | return hasMethodOrClassAnnotation.apply(description);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/android/suitebuilder/annotation/JUnit4HasClassAnnotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.uphyca.testing.android.suitebuilder.annotation;
18 |
19 | import java.lang.annotation.Annotation;
20 |
21 | import org.junit.runner.Description;
22 |
23 | import com.android.internal.util.Predicate;
24 |
25 | /**
26 | * Modified version of android.test.suitebuilder.annotation.HasAnnotation.
27 | *
28 | *
29 | * A predicate that checks to see if a {@link android.test.suitebuilder.TestMethod} has a specific annotation on the
30 | * containing class. Consider using the public {@link JUnit4HasAnnotation} class instead of this class.
31 | *
32 | * {@hide} Not needed for 1.0 SDK.
33 | */
34 | class JUnit4HasClassAnnotation implements Predicate {
35 |
36 | private Class extends Annotation> annotationClass;
37 |
38 | public JUnit4HasClassAnnotation(Class extends Annotation> annotationClass) {
39 | this.annotationClass = annotationClass;
40 | }
41 |
42 | public boolean apply(Description description) {
43 | return description.getTestClass().getAnnotation(annotationClass) != null;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/android/suitebuilder/annotation/JUnit4HasMethodAnnotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.uphyca.testing.android.suitebuilder.annotation;
18 |
19 | import java.lang.annotation.Annotation;
20 | import java.lang.reflect.Method;
21 |
22 | import org.junit.runner.Description;
23 |
24 | import android.test.suitebuilder.TestMethod;
25 |
26 | import com.android.internal.util.Predicate;
27 |
28 | /**
29 | * Modified version of android.test.suitebuilder.annotation.HasAnnotation.
30 | *
31 | *
32 | * A predicate that checks to see if a the method represented by {@link TestMethod} has a certain
33 | * annotation on it. Consider using the public {@link JUnit4HasAnnotation} class instead of this class.
34 | *
35 | * {@hide} Not needed for 1.0 SDK.
36 | */
37 | class JUnit4HasMethodAnnotation implements Predicate {
38 |
39 | private final Class extends Annotation> annotationClass;
40 |
41 | public JUnit4HasMethodAnnotation(Class extends Annotation> annotationClass) {
42 | this.annotationClass = annotationClass;
43 | }
44 |
45 | public boolean apply(Description description) {
46 | Method method;
47 |
48 | //For Parametarized
49 | String methodName = description.getMethodName();
50 | if (methodName == null) {
51 | return false;
52 | }
53 |
54 | int parameterIndex = methodName.indexOf('[');
55 | if (parameterIndex > -1) {
56 | methodName = methodName.substring(0, parameterIndex);
57 | }
58 |
59 | try {
60 | method = description.getTestClass().getMethod(methodName);
61 | } catch (NoSuchMethodException e) {
62 | //throw new RuntimeException(description.toString(), e);
63 | return false;
64 | }
65 | // if (method == null){
66 | // throw new RuntimeException("No such method for " + description);
67 | // }
68 | return method.getAnnotation(annotationClass) != null;
69 | // return description.getAnnotation(annotationClass) != null;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/junit/internal/builders/AndroidAllDefaultPossibilitiesBuilder.java:
--------------------------------------------------------------------------------
1 | package com.uphyca.testing.junit.internal.builders;
2 |
3 | import org.junit.internal.builders.AllDefaultPossibilitiesBuilder;
4 | import org.junit.internal.builders.AnnotatedBuilder;
5 | import org.junit.internal.builders.JUnit3Builder;
6 |
7 | /**
8 | * Modified version of
9 | * org.junit.internal.builders.AllDefaultPossibilitiesBuilder.
10 | */
11 | public class AndroidAllDefaultPossibilitiesBuilder extends AllDefaultPossibilitiesBuilder {
12 |
13 | public AndroidAllDefaultPossibilitiesBuilder(boolean canUseSuiteMethod) {
14 | super(canUseSuiteMethod);
15 | }
16 |
17 | @Override
18 | protected AnnotatedBuilder annotatedBuilder() {
19 | return new AndroidAnnotatedBuilder(this);
20 | }
21 |
22 | @Override
23 | protected JUnit3Builder junit3Builder() {
24 | return new AndroidJUnit3Builder();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/junit/internal/builders/AndroidAnnotatedBuilder.java:
--------------------------------------------------------------------------------
1 | package com.uphyca.testing.junit.internal.builders;
2 |
3 | import org.junit.internal.builders.AnnotatedBuilder;
4 | import org.junit.runner.RunWith;
5 | import org.junit.runner.Runner;
6 | import org.junit.runners.Suite;
7 | import org.junit.runners.model.InitializationError;
8 | import org.junit.runners.model.RunnerBuilder;
9 |
10 | import com.uphyca.testing.junit.runners.AndroidSuite;
11 |
12 | public class AndroidAnnotatedBuilder extends AnnotatedBuilder {
13 |
14 | private static final String CONSTRUCTOR_ERROR_FORMAT = "Custom runner class %s should have a public constructor with signature %s(Class testClass)";
15 |
16 | private RunnerBuilder fSuiteBuilder;
17 |
18 | public AndroidAnnotatedBuilder(RunnerBuilder suiteBuilder) {
19 | super(suiteBuilder);
20 | fSuiteBuilder = suiteBuilder;
21 | }
22 |
23 | @Override
24 | public Runner runnerForClass(Class> testClass) throws Exception {
25 | RunWith annotation = testClass.getAnnotation(RunWith.class);
26 | if (annotation != null) {
27 | //For Android
28 | Class extends Runner> runnerClass = useAndroidRunner(annotation.value());
29 | return buildRunner(runnerClass,
30 | testClass);
31 | }
32 | return null;
33 | }
34 |
35 | public Runner buildRunner(Class extends Runner> runnerClass,
36 | Class> testClass) throws Exception {
37 | try {
38 | return runnerClass.getConstructor(Class.class).newInstance(new Object[] { testClass });
39 | } catch (NoSuchMethodException e) {
40 | try {
41 | return runnerClass.getConstructor(Class.class,
42 | RunnerBuilder.class).newInstance(new Object[] { testClass, fSuiteBuilder });
43 | } catch (NoSuchMethodException e2) {
44 | String simpleName = runnerClass.getSimpleName();
45 | throw new InitializationError(String.format(CONSTRUCTOR_ERROR_FORMAT,
46 | simpleName,
47 | simpleName));
48 | }
49 | }
50 | }
51 |
52 | //For Android
53 | private Class extends Runner> useAndroidRunner(Class extends Runner> runnerClass) {
54 | if (runnerClass.equals(Suite.class)) {
55 | return AndroidSuite.class;
56 | }
57 | return runnerClass;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/junit/internal/builders/AndroidJUnit3Builder.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | package com.uphyca.testing.junit.internal.builders;
5 |
6 | import org.junit.internal.builders.JUnit3Builder;
7 | import org.junit.runner.Runner;
8 |
9 | import com.uphyca.testing.junit.internal.runners.AndroidJUnit38ClassRunner;
10 |
11 | /**
12 | * Modified version of org.junit.internal.builders.JUnit3Builder.
13 | */
14 | public class AndroidJUnit3Builder extends JUnit3Builder {
15 | @Override
16 | public Runner runnerForClass(Class> testClass) throws Throwable {
17 | if (isPre4Test(testClass)) {
18 | //For Android
19 | return new AndroidJUnit38ClassRunner(testClass);
20 | }
21 | return null;
22 | }
23 |
24 | boolean isPre4Test(Class> testClass) {
25 | return junit.framework.TestCase.class.isAssignableFrom(testClass);
26 | }
27 | }
--------------------------------------------------------------------------------
/android-junit4/src/main/java/com/uphyca/testing/junit/internal/requests/AndroidClassRequest.java:
--------------------------------------------------------------------------------
1 | package com.uphyca.testing.junit.internal.requests;
2 |
3 | import org.junit.internal.requests.ClassRequest;
4 | import org.junit.runner.Runner;
5 |
6 | import com.uphyca.testing.junit.internal.builders.AndroidAllDefaultPossibilitiesBuilder;
7 |
8 | public class AndroidClassRequest extends ClassRequest {
9 |
10 | private final Class> fTestClass;
11 |
12 | private boolean fCanUseSuiteMethod;
13 |
14 | public AndroidClassRequest(Class> testClass,
15 | boolean canUseSuiteMethod) {
16 | super(testClass, canUseSuiteMethod);
17 | fTestClass = testClass;
18 | fCanUseSuiteMethod = canUseSuiteMethod;
19 | }
20 |
21 | public AndroidClassRequest(Class> testClass) {
22 | this(testClass, true);
23 | }
24 |
25 | @Override
26 | public Runner getRunner() {
27 | // For Android
28 | return new AndroidAllDefaultPossibilitiesBuilder(fCanUseSuiteMethod).safeRunnerForClass(fTestClass);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 | com.uphyca
5 | android-junit4-parent
6 | 0.6-SNAPSHOT
7 | pom
8 | Android JUnit4(Parent)
9 |
10 | Tools for Android testing with JUnit4
11 | https://github.com/esmasui/AndroidJUnit4
12 |
13 |
14 | UTF-8
15 |
16 |
17 |
18 | https://github.com/esmasui/AndroidJUnit4/
19 | scm:git:git://github.com/esmasui/AndroidJUnit4.git
20 | scm:git:ssh://git@github.com/esmasui/AndroidJUnit4.git
21 | HEAD
22 |
23 |
24 |
25 | GitHub Issues
26 | https://github.com/esmasui/AndroidJUnit4/issues
27 |
28 |
29 |
30 |
31 | The Apache Software License, Version 2.0
32 | http://www.apache.org/licenses/LICENSE-2.0.txt
33 | repo
34 |
35 |
36 |
37 | uPhyca Inc.
38 | http://www.uphyca.com/
39 |
40 |
41 |
42 | org.sonatype.oss
43 | oss-parent
44 | 7
45 |
46 |
47 |
48 | android-junit4
49 | android-junit4-robolectric
50 | android-junit3-extension
51 | android-junit3-extension-support-v4
52 | android-junit3-dbunit
53 | android-junit4-extension
54 | android-junit4-extension-support-v4
55 |
56 | android-junit4-test
57 | android-junit3-extension-support-v4-test
58 | android-junit4-test-mockito
59 | android-junit3-dbunit-test
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------