Home | History | Annotate | Download | only in targetprep
      1 /*
      2  * Copyright (C) 2012 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 com.android.tradefed.targetprep;
     18 
     19 import com.android.tradefed.device.DeviceNotAvailableException;
     20 import com.android.tradefed.device.ITestDevice;
     21 
     22 import junit.framework.TestCase;
     23 
     24 import org.easymock.EasyMock;
     25 
     26 /**
     27  * Unit tests for {@link StopServicesSetup}
     28  */
     29 public class StopServicesSetupTest extends TestCase {
     30 
     31     private StopServicesSetup mPreparer = null;
     32     private ITestDevice mMockDevice = null;
     33 
     34     /**
     35      * {@inheritDoc}
     36      */
     37     @Override
     38     protected void setUp() throws Exception {
     39         super.setUp();
     40         mMockDevice = EasyMock.createStrictMock(ITestDevice.class);
     41         mPreparer = new StopServicesSetup();
     42     }
     43 
     44     /**
     45      * Test that the framework is stopped in the default case.
     46      */
     47     public void testNoop() throws DeviceNotAvailableException {
     48         EasyMock.expect(mMockDevice.executeShellCommand("stop")).andReturn(null);
     49 
     50         EasyMock.replay(mMockDevice);
     51         mPreparer.setUp(mMockDevice, null);
     52         EasyMock.verify(mMockDevice);
     53     }
     54 
     55     /**
     56      * Test that stopping the framework can be overwritten.
     57      */
     58     public void testNoStopFramework() throws DeviceNotAvailableException {
     59         mPreparer.setStopFramework(false);
     60 
     61         EasyMock.replay(mMockDevice);
     62         mPreparer.setUp(mMockDevice, null);
     63         EasyMock.verify(mMockDevice);
     64     }
     65 
     66     /**
     67      * Test that additional services are stopped if specified.
     68      */
     69     public void testStopServices() throws DeviceNotAvailableException {
     70         mPreparer.addService("service1");
     71         mPreparer.addService("service2");
     72 
     73         EasyMock.expect(mMockDevice.executeShellCommand("stop")).andReturn(null);
     74         EasyMock.expect(mMockDevice.executeShellCommand("stop service1")).andReturn(null);
     75         EasyMock.expect(mMockDevice.executeShellCommand("stop service2")).andReturn(null);
     76 
     77         EasyMock.replay(mMockDevice);
     78         mPreparer.setUp(mMockDevice, null);
     79         EasyMock.verify(mMockDevice);
     80     }
     81 }
     82 
     83