How to use method of org.easymock.android.AndroidTck class

Best Easymock code snippet using org.easymock.android.AndroidTck.

Run Easymock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1/*
2 * Copyright 2013-2021 the original author or authors.
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 */
16package org.easymock.android;
17
18import android.app.Activity;
19import android.app.Instrumentation;
20import android.os.Bundle;
21import android.os.Parcel;
22import android.os.Parcelable;
23
24import java.io.ByteArrayOutputStream;
25import java.io.PrintStream;
26import java.io.UnsupportedEncodingException;
27import java.nio.charset.Charset;
28
29import static org.easymock.EasyMock.*;
30
31/**
32 * Tests making sure EasyMock behave correctly on Android
33 *
34 * @author Henri Tremblay
35 */
36public class AndroidTck extends Instrumentation {
37
38    @Override
39   public void onCreate(Bundle arguments) {
40      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
41      PrintStream printStream;
42      try {
43         printStream = new PrintStream(outputStream, true, Charset.defaultCharset().name());
44      } catch (UnsupportedEncodingException e) {
45         throw new RuntimeException(e);
46      }
47      System.setOut(printStream);
48
49      System.setProperty("dexmaker.dexcache", getTargetContext().getCacheDir().getPath());
50
51      testInterface();
52      testObject();
53
54      Bundle bundle = new Bundle();
55      String fromStdout;
56      try {
57         fromStdout = outputStream.toString(Charset.defaultCharset().name());
58      } catch (UnsupportedEncodingException e) {
59         throw new RuntimeException(e);
60      }
61      bundle.putString(Instrumentation.REPORT_KEY_STREAMRESULT, fromStdout);
62      finish(Activity.RESULT_OK, bundle);
63   }
64
65   private void testObject() {
66      Activity mock = createMock(Activity.class);
67      mock.onLowMemory();
68      expect(mock.getTaskId()).andReturn(10);
69      System.out.println("replay");
70      replay(mock);
71      mock.onLowMemory();
72      if(mock.getTaskId() != 10) {
73          throw new AssertionError("Should have been 10");
74      }
75      System.out.println("verify");
76      verify(mock);
77   }
78
79   private void testInterface() {
80      Parcelable mock = createMock(Parcelable.class);
81      mock.writeToParcel(anyObject(Parcel.class), eq(4));
82      expect(mock.describeContents()).andReturn(11);
83      System.out.println("replay");
84      replay(mock);
85      mock.writeToParcel(null, 4);
86      if(mock.describeContents() != 11) {
87          throw new AssertionError("Should have been 11");
88      }
89      System.out.println("verify");
90      verify(mock);
91   }
92}
93
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in AndroidTck

Trigger code on LambdaTest Cloud Grid

Execute automation tests with on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)