1 /* 2 * Copyright 2010 Google Inc. 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 package com.google.android.testing.mocking; 17 18 import junit.framework.TestCase; 19 20 import java.util.Arrays; 21 import java.util.List; 22 23 /** 24 * @author swoodward@google.com (Stephen Woodward) 25 */ 26 public class SdkVersionTest extends TestCase { 27 testGetAllVersions()28 public void testGetAllVersions() { 29 List<SdkVersion> versions = Arrays.asList(SdkVersion.getAllVersions()); 30 List<SdkVersion> values = Arrays.asList(SdkVersion.values()); 31 assertEquals(6, versions.size()); 32 assertTrue(values.containsAll(versions)); 33 assertFalse(versions.contains(SdkVersion.UNKNOWN)); 34 } 35 testGetVersionName()36 public void testGetVersionName() { 37 assertEquals("v15", SdkVersion.CUPCAKE.getVersionName()); 38 assertEquals("v16", SdkVersion.DONUT.getVersionName()); 39 assertEquals("v201", SdkVersion.ECLAIR_0_1.getVersionName()); 40 assertEquals("v21", SdkVersion.ECLAIR_MR1.getVersionName()); 41 assertEquals("v22", SdkVersion.FROYO.getVersionName()); 42 assertEquals("v23", SdkVersion.GINGERBREAD.getVersionName()); 43 assertEquals("", SdkVersion.UNKNOWN.getVersionName()); 44 assertEquals("Unknown new SDK has been added, update this test", 45 7, SdkVersion.values().length); 46 } 47 testGetPackagePrefix()48 public void testGetPackagePrefix() { 49 assertEquals("v15.", SdkVersion.CUPCAKE.getPackagePrefix()); 50 assertEquals("v16.", SdkVersion.DONUT.getPackagePrefix()); 51 assertEquals("v201.", SdkVersion.ECLAIR_0_1.getPackagePrefix()); 52 assertEquals("v21.", SdkVersion.ECLAIR_MR1.getPackagePrefix()); 53 assertEquals("v22.", SdkVersion.FROYO.getPackagePrefix()); 54 assertEquals("v23.", SdkVersion.GINGERBREAD.getPackagePrefix()); 55 assertEquals("", SdkVersion.UNKNOWN.getPackagePrefix()); 56 assertEquals("Unknown new SDK has been added, update this test", 57 7, SdkVersion.values().length); 58 } 59 testGetCurrentVersion()60 public void testGetCurrentVersion() { 61 // Always UNKNOWN on the desktop 62 assertEquals(SdkVersion.UNKNOWN, SdkVersion.getCurrentVersion()); 63 } 64 testGetVersionFor()65 public void testGetVersionFor() { 66 assertEquals(SdkVersion.CUPCAKE, SdkVersion.getVersionFor(3)); 67 assertEquals(SdkVersion.DONUT, SdkVersion.getVersionFor(4)); 68 assertEquals(SdkVersion.ECLAIR_0_1, SdkVersion.getVersionFor(6)); 69 assertEquals(SdkVersion.ECLAIR_MR1, SdkVersion.getVersionFor(7)); 70 assertEquals(SdkVersion.FROYO, SdkVersion.getVersionFor(8)); 71 assertEquals(SdkVersion.GINGERBREAD, SdkVersion.getVersionFor(9)); 72 assertEquals(SdkVersion.UNKNOWN, SdkVersion.getVersionFor(-1)); 73 // All likely future version numbers... Modify this when a new version is added 74 for (int i = 10; i < 50; ++i) { 75 assertEquals("Unknown new SDK has been added, update this test", 76 SdkVersion.UNKNOWN, SdkVersion.getVersionFor(i)); 77 } 78 } 79 } 80