Home | History | Annotate | Download | only in build
      1 /*
      2  * Copyright (C) 2011 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 package com.android.tradefed.build;
     17 
     18 import com.android.tradefed.util.CommandResult;
     19 import com.android.tradefed.util.CommandStatus;
     20 import com.android.tradefed.util.IRunUtil;
     21 
     22 import junit.framework.TestCase;
     23 
     24 import org.easymock.EasyMock;
     25 
     26 import java.io.File;
     27 
     28 /**
     29  * Unit tests for {@link SdkBuildInfo}.
     30  */
     31 public class SdkBuildInfoTest extends TestCase {
     32 
     33     private IRunUtil mMockRunUtil;
     34     private SdkBuildInfo mSdkBuild;
     35 
     36     @Override
     37     protected void setUp() throws Exception {
     38         mMockRunUtil = EasyMock.createMock(IRunUtil.class);
     39         mSdkBuild =
     40                 new SdkBuildInfo() {
     41                     private static final long serialVersionUID = BuildSerializedVersion.VERSION;
     42 
     43                     @Override
     44                     IRunUtil getRunUtil() {
     45                         return mMockRunUtil;
     46                     }
     47                 };
     48         mSdkBuild.setSdkDir(new File("tmp"));
     49     }
     50     /**
     51      * Test success case for {@link SdkBuildInfo#getSdkTargets()}.
     52      */
     53     public void testGetSdkTargets() {
     54         CommandResult result = new CommandResult();
     55         result.setStdout("android-1\nandroid-2\n");
     56         result.setStatus(CommandStatus.SUCCESS);
     57         // expect the 'android list targets --compact' call
     58         EasyMock.expect(mMockRunUtil.runTimedCmd(EasyMock.anyLong(),
     59                 (String)EasyMock.anyObject() /* android */,
     60                 (String)EasyMock.anyObject(), /* list */
     61                 (String)EasyMock.anyObject(), /* targets */
     62                 (String)EasyMock.anyObject() /* --compact */)).andReturn(result);
     63         EasyMock.replay(mMockRunUtil);
     64         String[] targets = mSdkBuild.getSdkTargets();
     65         assertEquals("android-1", targets[0]);
     66         assertEquals("android-2", targets[1]);
     67     }
     68 }
     69