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.assertEquals; 20 import static org.junit.Assert.assertNotNull; 21 import static org.junit.Assert.assertNull; 22 23 import org.junit.Test; 24 25 import signature.comparator.util.AbstractComparatorTest; 26 import signature.compare.model.IApiDelta; 27 import signature.compare.model.DeltaType; 28 import signature.compare.model.IPackageDelta; 29 import signature.converter.util.CompilationUnit; 30 import signature.model.IApi; 31 32 import java.io.IOException; 33 34 public abstract class PackageCompareTest extends AbstractComparatorTest{ 35 36 @Test 37 public void compareEqualPackageTest0() throws IOException{ 38 CompilationUnit from = new CompilationUnit("a.A", 39 "package a; " + 40 "public class A {}"); 41 IApi fromApi = convert(from); 42 IApi toApi = convert(from); 43 IApiDelta delta = compare(fromApi, toApi); 44 assertNull(delta); 45 } 46 47 @Test 48 public void compareEqualPackageTest1() throws IOException{ 49 CompilationUnit from0 = new CompilationUnit("a.A", 50 "package a; " + 51 "public class A {}"); 52 CompilationUnit from1 = new CompilationUnit("a.b.A", 53 "package a.b; " + 54 "public class A {}"); 55 IApi fromApi = convert(from0, from1); 56 IApi toApi = convert(from0, from1); 57 assertNull(compare(fromApi, toApi)); 58 } 59 60 @Test 61 public void compareRemovedPackagePackageTest1() throws IOException{ 62 CompilationUnit packageA = new CompilationUnit("a.A", 63 "package a; " + 64 "public class A {}"); 65 CompilationUnit packageB = new CompilationUnit("a.b.A", 66 "package a.b; " + 67 "public class A {}"); 68 IApi fromApi = convert(packageA, packageB); 69 IApi toApi = convert(packageA); 70 IApiDelta apiDelta = compare(fromApi, toApi); 71 assertNotNull(apiDelta); 72 73 assertEquals(1, apiDelta.getPackageDeltas().size()); 74 IPackageDelta packageDelta = apiDelta.getPackageDeltas().iterator().next(); 75 assertEquals(DeltaType.REMOVED, packageDelta.getType()); 76 } 77 78 @Test 79 public void compareAddedPackagePackageTest1() throws IOException{ 80 CompilationUnit packageA = new CompilationUnit("a.A", 81 "package a; " + 82 "public class A {}"); 83 CompilationUnit packageB = new CompilationUnit("a.b.A", 84 "package a.b; " + 85 "public class A {}"); 86 IApi fromApi = convert(packageA); 87 IApi toApi = convert(packageA, packageB); 88 IApiDelta apiDelta = compare(fromApi, toApi); 89 assertNotNull(apiDelta); 90 91 assertEquals(1, apiDelta.getPackageDeltas().size()); 92 IPackageDelta packageDelta = apiDelta.getPackageDeltas().iterator().next(); 93 assertEquals(DeltaType.ADDED, packageDelta.getType()); 94 } 95 } 96