Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e35c13d0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make sure to remove final from nested classes too" into main

parents f992c647 e51562d9
Loading
Loading
Loading
Loading
+64 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.platform.test.ravenwood.RavenwoodRule;

import org.junit.Rule;
@@ -66,4 +67,67 @@ public class RavenwoodMockitoTest {

        assertThat(object.readInt()).isEqualTo(123);
    }

    public static final class MyFinalClass {
        public int getValue() {
            return 1;
        }
    }

    public static final class MyParcelable implements Parcelable {
        private final int mValue;

        public MyParcelable(int value) {
            mValue = value;
        }

        private MyParcelable(Parcel src) {
            mValue = src.readInt();
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(mValue);
        }

        public int getValue() {
            return mValue;
        }

        public static final Parcelable.Creator<MyParcelable> CREATOR =
                new Parcelable.Creator<>() {
                    public MyParcelable createFromParcel(Parcel in) {
                        return new MyParcelable(in);
                    }

                    public MyParcelable[] newArray(int size) {
                        return new MyParcelable[size];
                    }
                };
    }

    @Test
    public void testMockLocalFinalClass() {
        var p1 = mock(MyFinalClass.class);

        when(p1.getValue()).thenReturn(42);
        assertThat(p1.getValue()).isEqualTo(42);
    }

    @Test
    public void testMockLocalFinalParcelableClass() {
        // First, test the non-mock version, just in case.
        var p1 = new MyParcelable(1);
        assertThat(p1.getValue()).isEqualTo(1);

        var p2 = mock(MyParcelable.class);

        when(p2.getValue()).thenReturn(42);
        assertThat(p2.getValue()).isEqualTo(42);
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -99,6 +99,15 @@ class ImplGeneratingAdapter(
        return access
    }

    override fun visitInnerClass(
        name: String?,
        outerName: String?,
        innerName: String?,
        access: Int,
    ) {
        super.visitInnerClass(name, outerName, innerName, maybeRemoveFinalFromClass(access))
    }

    override fun visit(
        version: Int,
        origAccess: Int,
+3 −3
Original line number Diff line number Diff line
@@ -1774,7 +1774,7 @@ Constant pool:
}
InnerClasses:
  public static #x= #x of #x;            // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkLambdas.java"
RuntimeVisibleAnnotations:
  x: #x()
@@ -1963,7 +1963,7 @@ Constant pool:
}
InnerClasses:
  public static #x= #x of #x;           // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkLambdas.java"
RuntimeVisibleAnnotations:
  x: #x()
@@ -2271,7 +2271,7 @@ Constant pool:
InnerClasses:
  public static #x= #x of #x;           // ConstructorTester=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ConstructorTester of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static #x= #x of #x;            // ReplaceTo=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ReplaceTo of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkMethodCallReplace.java"
RuntimeVisibleAnnotations:
  x: #x()
+3 −3
Original line number Diff line number Diff line
@@ -2142,7 +2142,7 @@ Constant pool:
}
InnerClasses:
  public static #x= #x of #x;            // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkLambdas.java"
RuntimeVisibleAnnotations:
  x: #x()
@@ -2374,7 +2374,7 @@ Constant pool:
}
InnerClasses:
  public static #x= #x of #x;           // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkLambdas.java"
RuntimeVisibleAnnotations:
  x: #x()
@@ -2767,7 +2767,7 @@ Constant pool:
InnerClasses:
  public static #x= #x of #x;           // ConstructorTester=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ConstructorTester of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static #x= #x of #x;           // ReplaceTo=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ReplaceTo of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;          // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
SourceFile: "TinyFrameworkMethodCallReplace.java"
RuntimeVisibleAnnotations:
  x: #x()
+3 −3
Original line number Diff line number Diff line
@@ -1725,7 +1725,7 @@ BootstrapMethods:
      #x ()Ljava/lang/Integer;
InnerClasses:
  public static #x= #x of #x;          // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
## Class: com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas.class
  Compiled from "TinyFrameworkLambdas.java"
public class com.android.hoststubgen.test.tinyframework.TinyFrameworkLambdas
@@ -1882,7 +1882,7 @@ BootstrapMethods:
      #x ()Ljava/lang/Integer;
InnerClasses:
  public static #x= #x of #x;          // Nested=class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas$Nested of class com/android/hoststubgen/test/tinyframework/TinyFrameworkLambdas
  public static final #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;    // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
## Class: com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ConstructorTester.class
  Compiled from "TinyFrameworkMethodCallReplace.java"
public class com.android.hoststubgen.test.tinyframework.TinyFrameworkMethodCallReplace$ConstructorTester
@@ -2125,7 +2125,7 @@ BootstrapMethods:
InnerClasses:
  public static #x= #x of #x;          // ConstructorTester=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ConstructorTester of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static #x= #x of #x;          // ReplaceTo=class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace$ReplaceTo of class com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace
  public static final #x= #x of #x;   // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
  public static #x= #x of #x;   // Lookup=class java/lang/invoke/MethodHandles$Lookup of class java/lang/invoke/MethodHandles
## Class: com/android/hoststubgen/test/tinyframework/TinyFrameworkNative.class
  Compiled from "TinyFrameworkNative.java"
public class com.android.hoststubgen.test.tinyframework.TinyFrameworkNative
Loading