Home | History | Annotate | Download | only in plugins
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
      5  * except in compliance with the License. You may obtain a copy of the License at
      6  *
      7  *      http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the
     10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     11  * KIND, either express or implied. See the License for the specific language governing
     12  * permissions and limitations under the License.
     13  */
     14 
     15 package com.android.systemui.plugins;
     16 
     17 import static org.junit.Assert.assertFalse;
     18 import static org.junit.Assert.assertTrue;
     19 
     20 import android.support.test.filters.SmallTest;
     21 
     22 import com.android.systemui.SysuiTestCase;
     23 import com.android.systemui.plugins.VersionInfo.InvalidVersionException;
     24 import com.android.systemui.plugins.annotations.Requires;
     25 import com.android.systemui.plugins.qs.QS;
     26 import com.android.systemui.plugins.qs.DetailAdapter;
     27 import com.android.systemui.plugins.qs.QS.HeightListener;
     28 
     29 import org.junit.Rule;
     30 import org.junit.Test;
     31 import org.junit.rules.ExpectedException;
     32 
     33 @SmallTest
     34 public class VersionInfoTest extends SysuiTestCase {
     35 
     36     @Rule
     37     public ExpectedException mThrown = ExpectedException.none();
     38 
     39     @Test
     40     public void testHasInfo() {
     41         VersionInfo info = new VersionInfo();
     42         info.addClass(VersionInfoTest.class); // Has no annotations.
     43         assertFalse(info.hasVersionInfo());
     44 
     45         info.addClass(OverlayPlugin.class);
     46         assertTrue(info.hasVersionInfo());
     47     }
     48 
     49     @Test
     50     public void testSingleProvides() {
     51         VersionInfo overlay = new VersionInfo().addClass(OverlayPlugin.class);
     52         VersionInfo impl = new VersionInfo().addClass(OverlayImpl.class);
     53         overlay.checkVersion(impl);
     54     }
     55 
     56     @Test
     57     public void testIncorrectVersion() {
     58         VersionInfo overlay = new VersionInfo().addClass(OverlayPlugin.class);
     59         VersionInfo impl = new VersionInfo().addClass(OverlayImplIncorrectVersion.class);
     60         mThrown.expect(InvalidVersionException.class);
     61         overlay.checkVersion(impl);
     62     }
     63 
     64     @Test
     65     public void testMissingRequired() {
     66         VersionInfo overlay = new VersionInfo().addClass(OverlayPlugin.class);
     67         VersionInfo impl = new VersionInfo();
     68         mThrown.expect(InvalidVersionException.class);
     69         overlay.checkVersion(impl);
     70     }
     71 
     72     @Test
     73     public void testMissingDependencies() {
     74         VersionInfo overlay = new VersionInfo().addClass(QS.class);
     75         VersionInfo impl = new VersionInfo().addClass(QSImplNoDeps.class);
     76         mThrown.expect(InvalidVersionException.class);
     77         overlay.checkVersion(impl);
     78     }
     79 
     80     @Test
     81     public void testHasDependencies() {
     82         VersionInfo overlay = new VersionInfo().addClass(QS.class);
     83         VersionInfo impl = new VersionInfo().addClass(QSImpl.class);
     84         overlay.checkVersion(impl);
     85     }
     86 
     87     @Requires(target = OverlayPlugin.class, version = OverlayPlugin.VERSION)
     88     public static class OverlayImpl {
     89     }
     90 
     91     @Requires(target = OverlayPlugin.class, version = 0)
     92     public static class OverlayImplIncorrectVersion {
     93     }
     94 
     95     @Requires(target = QS.class, version = QS.VERSION)
     96     public static class QSImplNoDeps {
     97     }
     98 
     99     @Requires(target = QS.class, version = QS.VERSION)
    100     @Requires(target = HeightListener.class, version = HeightListener.VERSION)
    101     @Requires(target = DetailAdapter.class, version = DetailAdapter.VERSION)
    102     public static class QSImpl {
    103     }
    104 }
    105