Home | History | Annotate | Download | only in comparator
      1 /*
      2  * Copyright (C) 2009 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 signature.comparator;
     18 
     19 import static org.junit.Assert.assertNotNull;
     20 import static org.junit.Assert.assertNull;
     21 
     22 import org.junit.Test;
     23 
     24 import signature.comparator.util.AbstractComparatorTest;
     25 import signature.converter.util.CompilationUnit;
     26 import signature.model.IApi;
     27 
     28 import java.io.IOException;
     29 
     30 public abstract class AnnotationCompareTest extends AbstractComparatorTest {
     31 
     32     @Test
     33     public void testAnnotationValue() throws IOException{
     34         CompilationUnit A0 = new CompilationUnit("a.A0",
     35                 "package a; " +
     36                 "public @interface A0 {" +
     37                 "  A1 value() default @A1;" +
     38                 "}");
     39         CompilationUnit A1 = new CompilationUnit("a.A1",
     40                 "package a; " +
     41                 "public @interface A1 {" +
     42                 "}");
     43          CompilationUnit AnnotBDefault = new CompilationUnit("a.B",
     44                     "package a; " +
     45                     "@A0 " +
     46                     "public class B {}");
     47          CompilationUnit AnnotB = new CompilationUnit("a.B",
     48                     "package a; " +
     49                     "@A0 " +
     50                     "public class B {}");
     51           IApi fromApi = convert(A0, A1, AnnotBDefault);
     52           IApi toApi = convert(A0, A1, AnnotB);
     53           assertNull(compare(fromApi, toApi));
     54     }
     55 
     56        @Test
     57         public void testDefaultAnnotationValue() throws IOException{
     58              CompilationUnit A0 = new CompilationUnit("a.A0",
     59                     "package a; " +
     60                     "public @interface A0 {" +
     61                     "  String value() default \"bla\";" +
     62                     "}");
     63              CompilationUnit A1 = new CompilationUnit("a.A0",
     64                     "package a; " +
     65                     "public @interface A0 {" +
     66                     "  String value();" +
     67                     "}");
     68               IApi fromApi = convert(A0);
     69               IApi toApi = convert(A1);
     70               assertNotNull(compare(fromApi, toApi));
     71         }
     72 }
     73