1 /* 2 * Copyright (C) 2018 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.textclassifier.downloader; 18 19 import androidx.work.WorkInfo; 20 import androidx.work.WorkManager; 21 import androidx.work.WorkQuery; 22 import com.google.common.collect.ImmutableList; 23 import java.io.File; 24 import java.util.List; 25 26 /** Utils for downloader logic testing. */ 27 final class DownloaderTestUtils { 28 queryWorkInfos(WorkManager workManager, String queueName)29 public static List<WorkInfo> queryWorkInfos(WorkManager workManager, String queueName) 30 throws Exception { 31 WorkQuery workQuery = 32 WorkQuery.Builder.fromUniqueWorkNames(ImmutableList.of(queueName)).build(); 33 return workManager.getWorkInfos(workQuery).get(); 34 } 35 36 // MoreFiles#deleteRecursively is not available for Android guava. deleteRecursively(File f)37 public static void deleteRecursively(File f) { 38 if (f.isDirectory()) { 39 for (File innerFile : f.listFiles()) { 40 deleteRecursively(innerFile); 41 } 42 } 43 f.delete(); 44 } 45 DownloaderTestUtils()46 private DownloaderTestUtils() {} 47 } 48