Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2017 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.autofillservice.cts;
     18 
     19 import static org.mockito.Mockito.mock;
     20 import static org.testng.Assert.assertThrows;
     21 
     22 import android.platform.test.annotations.AppModeFull;
     23 import android.service.autofill.BatchUpdates;
     24 import android.service.autofill.CustomDescription;
     25 import android.service.autofill.InternalValidator;
     26 import android.service.autofill.Transformation;
     27 import android.service.autofill.Validator;
     28 import android.support.test.runner.AndroidJUnit4;
     29 import android.widget.RemoteViews;
     30 
     31 import org.junit.Test;
     32 import org.junit.runner.RunWith;
     33 
     34 @RunWith(AndroidJUnit4.class)
     35 @AppModeFull // Unit test
     36 public class CustomDescriptionUnitTest {
     37 
     38     private final CustomDescription.Builder mBuilder =
     39             new CustomDescription.Builder(mock(RemoteViews.class));
     40     private final BatchUpdates mValidUpdate =
     41             new BatchUpdates.Builder().updateTemplate(mock(RemoteViews.class)).build();
     42     private final Validator mValidCondition = mock(InternalValidator.class);
     43 
     44     @Test
     45     public void testNullConstructor() {
     46         assertThrows(NullPointerException.class, () ->  new CustomDescription.Builder(null));
     47     }
     48 
     49     @Test
     50     public void testAddChild_null() {
     51         assertThrows(IllegalArgumentException.class, () ->  mBuilder.addChild(42, null));
     52     }
     53 
     54     @Test
     55     public void testAddChild_invalidTransformation() {
     56         assertThrows(IllegalArgumentException.class,
     57                 () ->  mBuilder.addChild(42, mock(Transformation.class)));
     58     }
     59 
     60     @Test
     61     public void testBatchUpdate_nullCondition() {
     62         assertThrows(IllegalArgumentException.class,
     63                 () ->  mBuilder.batchUpdate(null, mValidUpdate));
     64     }
     65 
     66     @Test
     67     public void testBatchUpdate_invalidCondition() {
     68         assertThrows(IllegalArgumentException.class,
     69                 () ->  mBuilder.batchUpdate(mock(Validator.class), mValidUpdate));
     70     }
     71 
     72     @Test
     73     public void testBatchUpdate_nullUpdates() {
     74         assertThrows(NullPointerException.class,
     75                 () ->  mBuilder.batchUpdate(mValidCondition, null));
     76     }
     77 }
     78