1 /* 2 * Copyright (C) 2023 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 android.credentials.cts.unittests; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import static org.testng.Assert.assertThrows; 22 23 import android.credentials.ClearCredentialStateException; 24 import android.platform.test.annotations.AppModeFull; 25 26 import androidx.test.ext.junit.runners.AndroidJUnit4; 27 import androidx.test.filters.SmallTest; 28 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 32 33 @SmallTest 34 @AppModeFull(reason = "unit test") 35 @RunWith(AndroidJUnit4.class) 36 public class ClearCredentialStateExceptionTest { 37 38 @Test testConstructor_nullType()39 public void testConstructor_nullType() { 40 assertThrows(IllegalArgumentException.class, 41 () -> new ClearCredentialStateException(null, null, null)); 42 } 43 44 @Test testConstructor_type()45 public void testConstructor_type() { 46 final String type = ClearCredentialStateException.TYPE_UNKNOWN; 47 48 final ClearCredentialStateException exc = new ClearCredentialStateException(type); 49 50 assertThat(exc.getType()).isEqualTo(type); 51 assertThat(exc.getMessage()).isNull(); 52 assertThat(exc.getCause()).isNull(); 53 } 54 55 @Test testConstructor_type_message()56 public void testConstructor_type_message() { 57 final String type = ClearCredentialStateException.TYPE_UNKNOWN; 58 final String message = "message"; 59 60 final ClearCredentialStateException exc = new ClearCredentialStateException(type, message); 61 62 assertThat(exc.getType()).isEqualTo(type); 63 assertThat(exc.getMessage()).isEqualTo(message); 64 assertThat(exc.getCause()).isNull(); 65 } 66 67 @Test testConstructor_type_cause()68 public void testConstructor_type_cause() { 69 final String type = ClearCredentialStateException.TYPE_UNKNOWN; 70 final Throwable cause = new RuntimeException("cause"); 71 72 final ClearCredentialStateException exc = new ClearCredentialStateException(type, cause); 73 74 assertThat(exc.getType()).isEqualTo(type); 75 assertThat(exc.getMessage()).isNull(); 76 assertThat(exc.getCause()).isEqualTo(cause); 77 } 78 79 @Test testConstructor_type_message_cause()80 public void testConstructor_type_message_cause() { 81 final String type = ClearCredentialStateException.TYPE_UNKNOWN; 82 final String message = "message"; 83 final Throwable cause = new RuntimeException("cause"); 84 85 final ClearCredentialStateException exc = new ClearCredentialStateException(type, message, 86 cause); 87 88 assertThat(exc.getType()).isEqualTo(type); 89 assertThat(exc.getMessage()).isEqualTo(message); 90 assertThat(exc.getCause()).isEqualTo(cause); 91 } 92 } 93