2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.batch.actions.test;
24 import static org.junit.Assert.*;
25 import org.junit.After;
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.onap.aaf.auth.batch.actions.EmailPrint;
31 import org.onap.aaf.auth.env.AuthzTrans;
32 import org.onap.aaf.auth.org.Organization;
33 import org.onap.aaf.cadi.client.Future;
34 import org.onap.aaf.cadi.client.Rcli;
36 import static org.mockito.Mockito.*;
38 import java.io.ByteArrayOutputStream;
39 import java.io.PrintStream;
40 import java.lang.reflect.InvocationTargetException;
41 import java.lang.reflect.Method;
43 import org.junit.Test;
45 public class JU_EmailPrint {
47 private ByteArrayOutputStream outStream;
48 private ByteArrayOutputStream errStream;
52 StringBuilder strBuilder;
56 outStream = new ByteArrayOutputStream();
57 errStream = new ByteArrayOutputStream();
58 System.setOut(new PrintStream(outStream));
59 System.setErr(new PrintStream(errStream));
60 ePrint = new EmailPrint();
61 trans = mock(AuthzTrans.class);
62 org = mock(Organization.class);
63 strBuilder = new StringBuilder();
64 strBuilder.append("test\nte\nst");
66 ePrint.addTo("test1");
67 ePrint.addTo("test2");
69 ePrint.addCC("test1");
70 ePrint.addCC("test2");
75 public void testExec() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
76 Class c = ePrint.getClass();
77 Class[] cArg = new Class[3];
78 cArg[0] = AuthzTrans.class;
79 cArg[1] = Organization.class;
80 cArg[2] = StringBuilder.class;//Steps to test a protected method
81 Method execMethod = c.getDeclaredMethod("exec", cArg);
82 execMethod.setAccessible(true);
83 execMethod.invoke(ePrint, trans, org, strBuilder);
87 public void cleanUp() {
88 System.setErr(System.err);
89 System.setOut(System.out);