1 /* 2 * Copyright (C) 2022 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.android.wm.shell; 18 19 import static org.mockito.Mockito.RETURNS_SELF; 20 import static org.mockito.Mockito.doReturn; 21 import static org.mockito.Mockito.mock; 22 23 import android.view.SurfaceControl; 24 25 /** 26 * Helper class to provide mocks for {@link SurfaceControl.Builder} and 27 * {@link SurfaceControl.Transaction} with method chaining support. 28 */ 29 public class MockSurfaceControlHelper { MockSurfaceControlHelper()30 private MockSurfaceControlHelper() {} 31 32 /** 33 * Creates a mock {@link SurfaceControl.Builder} that supports method chaining and return the 34 * given {@link SurfaceControl} when calling {@link SurfaceControl.Builder#build()}. 35 * 36 * @param mockSurfaceControl the first {@link SurfaceControl} to return 37 * @return the mock of {@link SurfaceControl.Builder} 38 */ createMockSurfaceControlBuilder( SurfaceControl mockSurfaceControl)39 public static SurfaceControl.Builder createMockSurfaceControlBuilder( 40 SurfaceControl mockSurfaceControl) { 41 final SurfaceControl.Builder mockBuilder = mock(SurfaceControl.Builder.class, RETURNS_SELF); 42 doReturn(mockSurfaceControl) 43 .when(mockBuilder) 44 .build(); 45 return mockBuilder; 46 } 47 48 /** 49 * Creates a mock {@link SurfaceControl.Transaction} that supports method chaining. 50 * @return the mock of {@link SurfaceControl.Transaction} 51 */ createMockSurfaceControlTransaction()52 public static SurfaceControl.Transaction createMockSurfaceControlTransaction() { 53 return mock(SurfaceControl.Transaction.class, RETURNS_SELF); 54 } 55 } 56