1 /* 2 * Copyright (C) 2017 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.result; 18 19 import com.android.ddmlib.testrunner.TestIdentifier; 20 import com.android.tradefed.profiler.IAggregatingTestProfiler; 21 import com.android.tradefed.profiler.MetricOutputData; 22 23 import org.easymock.EasyMock; 24 import org.junit.Before; 25 import org.junit.Test; 26 import org.junit.runner.RunWith; 27 import org.junit.runners.JUnit4; 28 29 @RunWith(JUnit4.class) 30 public class AggregatingProfilerListenerTest { 31 32 private IAggregatingTestProfiler mMockProfiler = 33 EasyMock.createMock(IAggregatingTestProfiler.class); 34 private AggregatingProfilerListener mListener; 35 private MetricOutputData mData; 36 37 @Before 38 public void setUp() throws Exception { 39 mData = new MetricOutputData(); 40 EasyMock.expect(mMockProfiler.getMetricOutputUtil()).andReturn(mData); 41 EasyMock.replay(mMockProfiler); 42 mListener = new AggregatingProfilerListener(mMockProfiler); 43 EasyMock.reset(mMockProfiler); 44 } 45 46 @Test 47 public void testTestStarted() throws Exception { 48 mMockProfiler.startRecordingMetrics(); 49 EasyMock.expectLastCall(); 50 EasyMock.replay(mMockProfiler); 51 mListener.testStarted(new TestIdentifier("a", "b")); 52 EasyMock.verify(mMockProfiler); 53 } 54 55 @Test 56 public void testTestEnded() throws Exception { 57 TestIdentifier id = new TestIdentifier("a", "b"); 58 EasyMock.expect(mMockProfiler.stopRecordingMetrics(EasyMock.eq(id))).andReturn(null); 59 EasyMock.replay(mMockProfiler); 60 mListener.testEnded(id, null); 61 EasyMock.verify(mMockProfiler); 62 } 63 }