public final class

GeneralClickActionRemoteMessage

extends java.lang.Object

implements EspressoRemoteMessage.To<MessageLite>

 java.lang.Object

↳androidx.test.espresso.action.GeneralClickActionRemoteMessage

Gradle dependencies

compile group: 'androidx.test.espresso', name: 'espresso-remote', version: '3.6.1'

  • groupId: androidx.test.espresso
  • artifactId: espresso-remote
  • version: 3.6.1

Artifact androidx.test.espresso:espresso-remote:3.6.1 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test.espresso:espresso-remote com.android.support.test.espresso:espresso-remote

Androidx class mapping:

androidx.test.espresso.action.GeneralClickActionRemoteMessage android.support.test.espresso.action.GeneralClickActionRemoteMessage

Overview

and implementation of GeneralClickAction.

Summary

Fields
public static final EspressoRemoteMessage.From<ViewAction, MessageLite>FROM

This field is used to create an instance of this view action from its unwrapped proto message.

Constructors
publicGeneralClickActionRemoteMessage(GeneralClickAction generalClickAction)

Methods
public ViewActions.ClickViewActionPrototoProto()

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final EspressoRemoteMessage.From<ViewAction, MessageLite> FROM

This field is used to create an instance of this view action from its unwrapped proto message.

Constructors

public GeneralClickActionRemoteMessage(GeneralClickAction generalClickAction)

Methods

Source

/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package androidx.test.espresso.action;

import android.util.Log;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.proto.action.ViewActions.ClickViewActionProto;
import androidx.test.espresso.remote.EspressoRemoteMessage;
import com.google.protobuf.MessageLite;

/**
 * {@link EspressoRemoteMessage.To} and {@link EspressoRemoteMessage.From} implementation of {@link
 * GeneralClickAction}.
 */
public final class GeneralClickActionRemoteMessage
    implements EspressoRemoteMessage.To<MessageLite> {
  private static final String TAG = "GCARemoteMessage";

  private final CoordinatesProvider coordinatesProvider;
  private final Tapper tapper;
  private final PrecisionDescriber precisionDescriber;

  public GeneralClickActionRemoteMessage(GeneralClickAction generalClickAction) {
    this.tapper = generalClickAction.tapper;
    this.coordinatesProvider = generalClickAction.coordinatesProvider;
    this.precisionDescriber = generalClickAction.precisionDescriber;
  }

  @Override
  public ClickViewActionProto toProto() {
    try {
      return ClickViewActionProto.newBuilder()
          .setId(GeneralClickAction.class.getCanonicalName())
          .setTap(new TapRemoteMessage((Tap) tapper).toProto())
          .setLocation(
              new GeneralLocationRemoteMessage((GeneralLocation) coordinatesProvider).toProto())
          .setPrecision(new PressRemoteMessage((Press) precisionDescriber).toProto())
          .build();
    } catch (ClassCastException cce) {
      Log.e(
          TAG,
          "Your implementation is not compatible with Espresso Remote. Implement the"
              + "EspressoRemoteMessage.To interface in your custom Tapper, CoordinatesProvider or"
              + "PrecisionDescriber");
      // TODO: We might want to replace this a custom Espresso remote exception.
      throw cce;
    }
  }

  /**
   * This field is used to create an instance of this view action from its unwrapped proto message.
   */
  public static final EspressoRemoteMessage.From<ViewAction, MessageLite> FROM =
      new EspressoRemoteMessage.From<ViewAction, MessageLite>() {
        @Override
        public ViewAction fromProto(MessageLite messageLite) {
          ClickViewActionProto clickViewActionMessage = (ClickViewActionProto) messageLite;

          Tapper tapper = TapRemoteMessage.FROM.fromProto(clickViewActionMessage.getTap());

          CoordinatesProvider coordinatesProvider =
              GeneralLocationRemoteMessage.FROM.fromProto(clickViewActionMessage.getLocation());

          PrecisionDescriber precisionDescriber =
              PressRemoteMessage.FROM.fromProto(clickViewActionMessage.getPrecision());

          return new GeneralClickAction(tapper, coordinatesProvider, precisionDescriber);
        }
      };
}