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.managedprovisioning.task; 18 19 import static java.util.Objects.requireNonNull; 20 21 import android.content.Context; 22 23 import com.android.managedprovisioning.model.ProvisioningParams; 24 25 import java.util.function.Consumer; 26 27 /** 28 * A mock {@link AbstractProvisioningTask}. 29 */ 30 public final class MockTask extends AbstractProvisioningTask { 31 private final Consumer<AbstractProvisioningTask> mConsumer; 32 33 /** 34 * Constructs a {@link MockTask} with a given {@link Consumer} to execute in its {@link #run} 35 * method. 36 */ MockTask( Context context, ProvisioningParams provisioningParams, Callback callback, Consumer<AbstractProvisioningTask> consumer)37 public MockTask( 38 Context context, 39 ProvisioningParams provisioningParams, 40 Callback callback, 41 Consumer<AbstractProvisioningTask> consumer) { 42 super(context, provisioningParams, callback); 43 mConsumer = requireNonNull(consumer); 44 } 45 46 @Override run(int userId)47 public void run(int userId) { 48 mConsumer.accept(this); 49 } 50 } 51