1f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project/*
2f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * Copyright (C) 2009 The Android Open Source Project
3f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project *
4f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License");
5f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * you may not use this file except in compliance with the License.
6f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * You may obtain a copy of the License at
7f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project *
8f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project *      http://www.apache.org/licenses/LICENSE-2.0
9f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project *
10f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * Unless required by applicable law or agreed to in writing, software
11f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS,
12f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * See the License for the specific language governing permissions and
14f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project * limitations under the License.
15f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project */
16f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
17f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectpackage signature.comparator;
18f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
19f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport static org.junit.Assert.assertEquals;
20f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport static org.junit.Assert.assertNotNull;
21f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport static org.junit.Assert.assertNull;
22f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
23f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport org.junit.Test;
24f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
25f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport signature.comparator.util.AbstractComparatorTest;
26f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport signature.compare.model.IApiDelta;
27f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport signature.compare.model.DeltaType;
28f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport signature.compare.model.IPackageDelta;
29f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport signature.converter.util.CompilationUnit;
30f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport signature.model.IApi;
31f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
32f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectimport java.io.IOException;
33f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
34f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Projectpublic abstract class PackageCompareTest extends AbstractComparatorTest{
35f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
36f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    @Test
37f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    public void compareEqualPackageTest0() throws IOException{
38f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project         CompilationUnit from = new CompilationUnit("a.A",
39f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "package a; " +
40f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "public class A {}");
41f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApi fromApi = convert(from);
42f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApi toApi = convert(from);
43f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApiDelta delta = compare(fromApi, toApi);
44f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          assertNull(delta);
45f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    }
46f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
47f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    @Test
48f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    public void compareEqualPackageTest1() throws IOException{
49f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project         CompilationUnit from0 = new CompilationUnit("a.A",
50f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "package a; " +
51f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "public class A {}");
52f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project         CompilationUnit from1 = new CompilationUnit("a.b.A",
53f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "package a.b; " +
54f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "public class A {}");
55f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApi fromApi = convert(from0, from1);
56f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApi toApi = convert(from0, from1);
57f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          assertNull(compare(fromApi, toApi));
58f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    }
59f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
60f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    @Test
61f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    public void compareRemovedPackagePackageTest1() throws IOException{
62f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project         CompilationUnit packageA = new CompilationUnit("a.A",
63f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "package a; " +
64f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "public class A {}");
65f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project         CompilationUnit packageB = new CompilationUnit("a.b.A",
66f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "package a.b; " +
67f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "public class A {}");
68f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApi fromApi = convert(packageA, packageB);
69f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApi toApi = convert(packageA);
70f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApiDelta apiDelta = compare(fromApi, toApi);
71f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          assertNotNull(apiDelta);
72f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
73f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          assertEquals(1, apiDelta.getPackageDeltas().size());
74f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IPackageDelta packageDelta = apiDelta.getPackageDeltas().iterator().next();
75f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          assertEquals(DeltaType.REMOVED, packageDelta.getType());
76f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    }
77f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
78f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    @Test
79f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    public void compareAddedPackagePackageTest1() throws IOException{
80f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project         CompilationUnit packageA = new CompilationUnit("a.A",
81f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "package a; " +
82f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "public class A {}");
83f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project         CompilationUnit packageB = new CompilationUnit("a.b.A",
84f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "package a.b; " +
85f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project                    "public class A {}");
86f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApi fromApi = convert(packageA);
87f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApi toApi = convert(packageA, packageB);
88f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IApiDelta apiDelta = compare(fromApi, toApi);
89f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          assertNotNull(apiDelta);
90f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project
91f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          assertEquals(1, apiDelta.getPackageDeltas().size());
92f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          IPackageDelta packageDelta = apiDelta.getPackageDeltas().iterator().next();
93f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project          assertEquals(DeltaType.ADDED, packageDelta.getType());
94f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project    }
95f8057104af9cae031b544e971a52adafa7c0d9eThe Android Open Source Project}
96