Home | History | Annotate | Download | only in result
      1 /*
      2  * Copyright (C) 2018 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.result;
     17 
     18 import com.android.ddmlib.testrunner.TestIdentifier;
     19 import com.android.tradefed.config.OptionSetter;
     20 import com.android.tradefed.invoker.InvocationContext;
     21 
     22 import org.easymock.EasyMock;
     23 import org.junit.Before;
     24 import org.junit.Test;
     25 import org.junit.runner.RunWith;
     26 import org.junit.runners.JUnit4;
     27 
     28 import java.util.Collections;
     29 
     30 import com.android.tradefed.util.SubprocessTestResultsParser;
     31 
     32 /**
     33  * Unit Tests for {@link LegacySubprocessResultsReporter} The tests are copied from {@link
     34  * SubprocessResultsReporterTest}
     35  */
     36 @RunWith(JUnit4.class)
     37 public class LegacySubprocessResultsReporterTest {
     38 
     39     private LegacySubprocessResultsReporter mReporter;
     40 
     41     @Before
     42     public void setUp() {
     43         mReporter = new LegacySubprocessResultsReporter();
     44     }
     45 
     46     /** Test deprecated method that when none of the option for reporting is set, nothing happen. */
     47     @Test
     48     public void testPrintEvent_Inop() {
     49         TestIdentifier testId = new TestIdentifier("com.fakeclass", "faketest");
     50         mReporter.testStarted(testId);
     51         mReporter.testFailed(testId, "fake failure");
     52         mReporter.testEnded(testId, Collections.emptyMap());
     53         mReporter.printEvent(null, null);
     54     }
     55 
     56     /**
     57      * Test deprecate method that events sent through the socket reporting part are received on the
     58      * other hand.
     59      */
     60     @Test
     61     public void testPrintEvent_printToSocket() throws Exception {
     62         TestIdentifier testId = new TestIdentifier("com.fakeclass", "faketest");
     63         TestDescription testDescrip = new TestDescription("com.fakeclass", "faketest");
     64         ITestInvocationListener mMockListener = EasyMock.createMock(ITestInvocationListener.class);
     65         SubprocessTestResultsParser receiver =
     66                 new SubprocessTestResultsParser(mMockListener, true, new InvocationContext());
     67         try {
     68             OptionSetter setter = new OptionSetter(mReporter);
     69             setter.setOptionValue(
     70                     "subprocess-report-port", Integer.toString(receiver.getSocketServerPort()));
     71             // mirror calls between receiver and sender.
     72             mMockListener.testIgnored(testDescrip);
     73             mMockListener.testAssumptionFailure(testDescrip, "fake trace");
     74             mMockListener.testRunFailed("no reason");
     75             mMockListener.invocationFailed((Throwable) EasyMock.anyObject());
     76             EasyMock.replay(mMockListener);
     77             mReporter.testIgnored(testId);
     78             mReporter.testAssumptionFailure(testId, "fake trace");
     79             mReporter.testRunFailed("no reason");
     80             mReporter.invocationFailed(new Throwable());
     81             mReporter.close();
     82             receiver.joinReceiver(500);
     83             EasyMock.verify(mMockListener);
     84         } finally {
     85             receiver.close();
     86         }
     87     }
     88 }
     89