Home | History | Annotate | Download | only in tzlookup
      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 com.android.libcore.timezone.tzlookup;
     18 
     19 import org.junit.Test;
     20 
     21 import static org.junit.Assert.assertFalse;
     22 import static org.junit.Assert.assertTrue;
     23 
     24 public class ErrorsTest {
     25 
     26     @Test
     27     public void warnings() {
     28         Errors errors = new Errors();
     29         assertTrue(errors.isEmpty());
     30         assertFalse(errors.hasError());
     31         assertFalse(errors.hasFatal());
     32 
     33         errors.addWarning("Hello");
     34         assertFalse(errors.isEmpty());
     35         assertFalse(errors.hasError());
     36         assertFalse(errors.hasFatal());
     37 
     38         TestUtils.assertContains(errors.asString(), "Hello");
     39     }
     40 
     41     @Test
     42     public void error() {
     43         Errors errors = new Errors();
     44         assertTrue(errors.isEmpty());
     45         assertFalse(errors.hasError());
     46         assertFalse(errors.hasFatal());
     47 
     48         errors.addError("Hello");
     49         assertFalse(errors.isEmpty());
     50         assertTrue(errors.hasError());
     51         assertFalse(errors.hasFatal());
     52 
     53         TestUtils.assertContains(errors.asString(), "Hello");
     54     }
     55 
     56     @Test
     57     public void fatal() {
     58         Errors errors = new Errors();
     59         assertTrue(errors.isEmpty());
     60         assertFalse(errors.hasError());
     61         assertFalse(errors.hasFatal());
     62 
     63         errors.addFatal("Hello");
     64         assertFalse(errors.isEmpty());
     65         assertTrue(errors.hasError());
     66         assertTrue(errors.hasFatal());
     67 
     68         TestUtils.assertContains(errors.asString(), "Hello");
     69     }
     70 
     71     @Test
     72     public void scope() {
     73         Errors errors = new Errors();
     74 
     75         errors.addWarning("Hello");
     76 
     77         errors.pushScope("Monty Python");
     78         errors.addError("John Cleese");
     79 
     80         errors.pushScope("Holy grail");
     81         errors.addFatal("Silly place");
     82         errors.popScope();
     83 
     84         errors.addError("Michael Palin");
     85 
     86         errors.pushScope("Parrot sketch");
     87         errors.addFatal("Fjords");
     88         errors.popScope();
     89 
     90         String[] lines = errors.asString().split("\n");
     91 
     92         String line0 = lines[0];
     93         TestUtils.assertContains(line0, "Hello");
     94         TestUtils.assertAbsent(line0, "Monty Python");
     95 
     96         String line1 = lines[1];
     97         TestUtils.assertContains(line1, "Monty Python");
     98         TestUtils.assertAbsent(line1, "Holy grail");
     99         TestUtils.assertContains(line1, "John Cleese");
    100 
    101         String line2 = lines[2];
    102         TestUtils.assertContains(line2, "Monty Python", "Holy grail");
    103         TestUtils.assertAbsent(line2, "Parrot sketch");
    104         TestUtils.assertContains(line2, "Silly place");
    105 
    106         String line3 = lines[3];
    107         TestUtils.assertContains(line3, "Monty Python");
    108         TestUtils.assertAbsent(line3, "Holy grail");
    109         TestUtils.assertContains(line3, "Michael Palin");
    110 
    111         String line4 = lines[4];
    112         TestUtils.assertContains(line4, "Monty Python", "Parrot sketch");
    113         TestUtils.assertAbsent(line4, "Holy grail");
    114         TestUtils.assertContains(line4, "Fjords");
    115     }
    116 
    117 }
    118