• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static com.google.common.truth.Truth.assertThat;
20 
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.junit.runners.JUnit4;
24 
25 @RunWith(JUnit4.class)
26 public final class ModelDownloadExceptionTest {
27   private static final int ERROR_CODE = ModelDownloadException.FAILED_TO_DOWNLOAD_OTHER;
28   private static final int DOWNLOADER_LIB_ERROR_CODE = 500;
29 
30   @Test
getErrorCode_constructor1()31   public void getErrorCode_constructor1() {
32     ModelDownloadException e = new ModelDownloadException(ERROR_CODE, new Exception());
33     assertThat(e.getErrorCode()).isEqualTo(ERROR_CODE);
34     assertThat(e.getDownloaderLibErrorCode())
35         .isEqualTo(ModelDownloadException.DEFAULT_DOWNLOADER_LIB_ERROR_CODE);
36   }
37 
38   @Test
getErrorCode_constructor2()39   public void getErrorCode_constructor2() {
40     ModelDownloadException e = new ModelDownloadException(ERROR_CODE, "error_msg");
41     assertThat(e.getErrorCode()).isEqualTo(ERROR_CODE);
42     assertThat(e.getDownloaderLibErrorCode())
43         .isEqualTo(ModelDownloadException.DEFAULT_DOWNLOADER_LIB_ERROR_CODE);
44   }
45 
46   @Test
getErrorCode_constructor3()47   public void getErrorCode_constructor3() {
48     ModelDownloadException e =
49         new ModelDownloadException(ERROR_CODE, DOWNLOADER_LIB_ERROR_CODE, "error_msg");
50     assertThat(e.getErrorCode()).isEqualTo(ERROR_CODE);
51     assertThat(e.getDownloaderLibErrorCode()).isEqualTo(DOWNLOADER_LIB_ERROR_CODE);
52   }
53 }
54