1 /* 2 * Copyright 2022 Google LLC 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 package com.google.android.libraries.mobiledatadownload.downloader; 17 18 import static com.google.android.libraries.mobiledatadownload.internal.MddConstants.INLINE_FILE_URL_SCHEME; 19 import static com.google.common.truth.Truth.assertThat; 20 import static org.junit.Assert.assertThrows; 21 22 import android.net.Uri; 23 import androidx.test.ext.junit.runners.AndroidJUnit4; 24 import com.google.android.libraries.mobiledatadownload.FileSource; 25 import com.google.protobuf.ByteString; 26 import org.junit.Test; 27 import org.junit.runner.RunWith; 28 29 @RunWith(AndroidJUnit4.class) 30 public final class DownloadRequestTest { 31 32 @Test build_whenInlineFileUrl_whenInlineDownloadParamsNotProvided_throws()33 public void build_whenInlineFileUrl_whenInlineDownloadParamsNotProvided_throws() { 34 assertThrows( 35 IllegalArgumentException.class, 36 () -> 37 DownloadRequest.newBuilder() 38 .setUrlToDownload("inlinefile:sha1:test") 39 .setFileUri( 40 Uri.parse( 41 "android://com.google.android.libraries.mobiledatadownload.downloader/test")) 42 .build()); 43 } 44 45 @Test build_whenInlineFileUrl_whenInlineDownloadParamsProvided_builds()46 public void build_whenInlineFileUrl_whenInlineDownloadParamsProvided_builds() { 47 DownloadRequest request = 48 DownloadRequest.newBuilder() 49 .setUrlToDownload("inlinefile:sha1:test") 50 .setFileUri( 51 Uri.parse( 52 "android://com.google.android.libraries.mobiledatadownload.downloader/test")) 53 .setInlineDownloadParamsOptional( 54 InlineDownloadParams.newBuilder() 55 .setInlineFileContent( 56 FileSource.ofByteString(ByteString.copyFromUtf8("TEST_CONTENT"))) 57 .build()) 58 .build(); 59 60 assertThat(request.inlineDownloadParamsOptional()).isPresent(); 61 assertThat(request.urlToDownload()).startsWith(INLINE_FILE_URL_SCHEME); 62 } 63 } 64