Skip to content

Commit

Permalink
[espresso] Enable warnings as errors (flutter#3414)
Browse files Browse the repository at this point in the history
[espresso] Enable warnings as errors
  • Loading branch information
navaronbracke committed Mar 9, 2023
1 parent 3b29183 commit eb2fe26
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 10 deletions.
4 changes: 3 additions & 1 deletion packages/espresso/CHANGELOG.md
@@ -1,5 +1,7 @@
## NEXT
## 0.3.0

* **BREAKING CHANGE**: Migrates uses of the deprecated `@Beta` annotation to the new `@ExperimentalApi` annotation.
* Changes the severity of `javac` warnings so that they are treated as errors and fixes the violations.
* Aligns Dart and Flutter SDK constraints.

## 0.2.1
Expand Down
Expand Up @@ -12,6 +12,7 @@

import android.util.Log;
import android.view.View;
import androidx.test.annotation.ExperimentalTestApi;
import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.flutter.action.FlutterViewAction;
Expand Down Expand Up @@ -99,6 +100,7 @@ private WidgetInteraction(
* @param widgetActions one or more actions that shall be performed. Cannot be {@code null}.
* @return this interaction for further perform/verification calls.
*/
@ExperimentalTestApi()
public WidgetInteraction perform(@Nonnull final WidgetAction... widgetActions) {
checkNotNull(widgetActions);
for (WidgetAction widgetAction : widgetActions) {
Expand All @@ -115,6 +117,7 @@ public WidgetInteraction perform(@Nonnull final WidgetAction... widgetActions) {
* @param assertion a widget assertion that shall be made on the matched Flutter widget. Cannot
* be {@code null}.
*/
@ExperimentalTestApi()
public WidgetInteraction check(@Nonnull WidgetAssertion assertion) {
checkNotNull(
assertion,
Expand All @@ -130,14 +133,15 @@ public WidgetInteraction check(@Nonnull WidgetAssertion assertion) {
return this;
}

@ExperimentalTestApi()
@SuppressWarnings("unchecked")
private <T> T performInternal(FlutterAction<T> flutterAction) {
checkNotNull(
flutterAction,
"The action cannot be null. You must specify an action to perform on the matched"
+ " Flutter widget.");
FlutterViewAction<T> flutterViewAction =
new FlutterViewAction(
new FlutterViewAction<>(
widgetMatcher, flutterAction, okHttpClient, idGenerator, taskExecutor);
onView(flutterViewMatcher).perform(flutterViewAction);
T result;
Expand Down
Expand Up @@ -4,6 +4,7 @@

package androidx.test.espresso.flutter.action;

import androidx.test.annotation.ExperimentalTestApi;
import androidx.test.espresso.flutter.api.WidgetAction;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -43,6 +44,7 @@ public static WidgetAction click() {
* by directly injecting key events to the Android system. Uses this {@link #syntheticClick()}
* only when there are special cases that {@link #click()} cannot handle properly.
*/
@ExperimentalTestApi()
public static WidgetAction syntheticClick() {
return new SyntheticClickAction();
}
Expand Down
Expand Up @@ -13,7 +13,7 @@

import android.os.Looper;
import android.view.View;
import androidx.test.annotation.Beta;
import androidx.test.annotation.ExperimentalTestApi;
import androidx.test.espresso.IdlingRegistry;
import androidx.test.espresso.IdlingResource;
import androidx.test.espresso.UiController;
Expand Down Expand Up @@ -47,7 +47,6 @@
* <p>This class acts as a bridge to perform {@code WidgetAction} on a Flutter widget on the given
* {@code FlutterView}.
*/
@Beta
public final class FlutterViewAction<T> implements ViewAction {

private static final String FLUTTER_IDLE_TASK_NAME = "flutterIdlingResource";
Expand Down Expand Up @@ -96,6 +95,7 @@ public String getDescription() {
"Perform a %s action on the Flutter widget matched %s.", widgetAction, widgetMatcher);
}

@ExperimentalTestApi
@Override
public void perform(UiController uiController, View flutterView) {
// There could be a gap between when the Flutter view is available in the view hierarchy and the
Expand All @@ -104,6 +104,9 @@ public void perform(UiController uiController, View flutterView) {
loopUntilFlutterViewRendered(flutterView, uiController);
// The url {@code FlutterNativeView} returns is the http url that the Dart VM Observatory http
// server serves at. Need to convert to the one that the WebSocket uses.

// TODO(stuartmorgan): migrate to getVMServiceUri() once that is available on stable.
@SuppressWarnings("deprecation")
URI dartVmServiceProtocolUrl =
DartVmServiceUtil.getServiceProtocolUri(FlutterJNI.getObservatoryUri());
String isolateId = DartVmServiceUtil.getDartIsolateId(flutterView);
Expand Down Expand Up @@ -136,6 +139,7 @@ public ListenableFuture<Void> apply(Void readyResult) {
}
}

@ExperimentalTestApi
@VisibleForTesting
void perform(
View flutterView, FlutterTestingProtocol flutterTestingProtocol, UiController uiController) {
Expand Down
Expand Up @@ -5,7 +5,7 @@
package androidx.test.espresso.flutter.action;

import android.view.View;
import androidx.test.annotation.Beta;
import androidx.test.annotation.ExperimentalTestApi;
import androidx.test.espresso.UiController;
import androidx.test.espresso.flutter.api.FlutterTestingProtocol;
import androidx.test.espresso.flutter.api.SyntheticAction;
Expand All @@ -21,9 +21,9 @@
* <p>Note, this is not a real click gesture event issued from Android system. Espresso delegates to
* Flutter engine to perform the {@link SyntheticClick} action.
*/
@Beta
public final class SyntheticClickAction implements WidgetAction {

@ExperimentalTestApi
@Override
public Future<Void> perform(
@Nullable WidgetMatcher targetWidget,
Expand Down
Expand Up @@ -13,6 +13,8 @@
public final class AmbiguousWidgetMatcherException extends RuntimeException
implements EspressoException {

private static final long serialVersionUID = 0L;

public AmbiguousWidgetMatcherException(String message) {
super(message);
}
Expand Down
Expand Up @@ -10,6 +10,8 @@
public final class InvalidFlutterViewException extends RuntimeException
implements EspressoException {

private static final long serialVersionUID = 0L;

/** Constructs with an error message. */
public InvalidFlutterViewException(String message) {
super(message);
Expand Down
Expand Up @@ -11,6 +11,7 @@
* hierarchy.
*/
public final class NoMatchingWidgetException extends RuntimeException implements EspressoException {
private static final long serialVersionUID = 0L;

public NoMatchingWidgetException(String message) {
super(message);
Expand Down
Expand Up @@ -6,6 +6,7 @@

/** Represents an exception/error relevant to Dart VM service. */
public final class FlutterProtocolException extends RuntimeException {
private static final long serialVersionUID = 0L;

public FlutterProtocolException(String message) {
super(message);
Expand Down
6 changes: 3 additions & 3 deletions packages/espresso/example/android/build.gradle
Expand Up @@ -35,9 +35,9 @@ task clean(type: Delete) {
gradle.projectsEvaluated {
project(":espresso") {
tasks.withType(JavaCompile) {
// TODO(stuartmorgan): Enable this. See
// https://github.com/flutter/flutter/issues/91868
//options.compilerArgs << "-Xlint:all" << "-Werror"
// Ignore classfile warnings due to https://bugs.openjdk.org/browse/JDK-8190452
// TODO(stuartmorgan): Remove that ignore once the build uses Java 11+.
options.compilerArgs << "-Xlint:all" << "-Werror" << "-Xlint:-classfile"
}
}
}
2 changes: 1 addition & 1 deletion packages/espresso/pubspec.yaml
Expand Up @@ -3,7 +3,7 @@ description: Java classes for testing Flutter apps using Espresso.
Allows driving Flutter widgets from a native Espresso test.
repository: https://github.com/flutter/packages/tree/main/packages/espresso
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+espresso%22
version: 0.2.1
version: 0.3.0

environment:
sdk: ">=2.17.0 <3.0.0"
Expand Down

0 comments on commit eb2fe26

Please sign in to comment.