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.result; 17 18 import junit.framework.TestCase; 19 20 /** 21 * Unit tests for {@link FailureEmailResultReporter}. 22 */ 23 public class FailureEmailResultReporterTest extends TestCase { 24 private class FakeEmailResultReporter extends FailureEmailResultReporter { 25 private boolean mHasFailedTests; 26 private InvocationStatus mInvocationStatus; 27 28 FakeEmailResultReporter(boolean hasFailedTests, InvocationStatus invocationStatus) { 29 mHasFailedTests = hasFailedTests; 30 mInvocationStatus = invocationStatus; 31 } 32 33 /** 34 * {@inheritDoc} 35 */ 36 @Override 37 public boolean hasFailedTests() { 38 return mHasFailedTests; 39 } 40 41 /** 42 * {@inheritDoc} 43 */ 44 @Override 45 public InvocationStatus getInvocationStatus() { 46 return mInvocationStatus; 47 } 48 } 49 50 /** 51 * Test that {@link FailureEmailResultReporter#shouldSendMessage()} returns true if 52 * {@link EmailResultReporter#getInvocationStatus()} is not {@link InvocationStatus#SUCCESS}. 53 */ 54 public void testShouldSendMessage() { 55 // Don't send email if there is no test failure and no invocation failure. 56 FakeEmailResultReporter r = new FakeEmailResultReporter(false, InvocationStatus.SUCCESS); 57 assertFalse(r.shouldSendMessage()); 58 59 // Send email if there is an invocation failure. 60 r = new FakeEmailResultReporter(false, InvocationStatus.BUILD_ERROR); 61 assertTrue(r.shouldSendMessage()); 62 63 // Send email if there is an invocation failure. 64 r = new FakeEmailResultReporter(false, InvocationStatus.FAILED); 65 assertTrue(r.shouldSendMessage()); 66 67 // Send email if there is an test failure. 68 r = new FakeEmailResultReporter(true, InvocationStatus.SUCCESS); 69 assertTrue(r.shouldSendMessage()); 70 71 // Send email if there is an test failure and an invocation failure. 72 r = new FakeEmailResultReporter(true, InvocationStatus.FAILED); 73 assertTrue(r.shouldSendMessage()); 74 } 75 }