Added oparent to sdc main
[sdc.git] / asdctool / src / test / java / org / openecomp / sdc / asdctool / migration / tasks / handlers / XlsOutputHandlerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.asdctool.migration.tasks.handlers;
22
23 import org.apache.poi.ss.usermodel.Workbook;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mock;
27 import org.mockito.Spy;
28 import org.mockito.junit.MockitoJUnitRunner;
29
30 import java.io.FileOutputStream;
31 import java.io.IOException;
32
33 import static org.junit.Assert.assertFalse;
34 import static org.junit.Assert.assertTrue;
35 import static org.mockito.ArgumentMatchers.any;
36 import static org.mockito.Mockito.*;
37
38 @RunWith(MockitoJUnitRunner.class)
39 public class XlsOutputHandlerTest {
40
41     @Spy
42     private XlsOutputHandler handler = new XlsOutputHandler(null, "mock");
43
44     @Mock
45     private Workbook workbook;
46     @Mock
47     private FileOutputStream xlsFile;
48
49     @Test
50     public void verifyThatFileIsNotCreatedIfNoRecordsAdded() throws IOException {
51         assertFalse(handler.writeOutputAndCloseFile());
52         verify(workbook, times(0)).write(any());
53     }
54
55     @Test
56     public void verifyThatFileIsCreatedIfSomeRecordsAdded() throws IOException {
57         handler.addRecord("mock");
58         doReturn(xlsFile).when(handler).getXlsFile();
59         assertTrue(handler.writeOutputAndCloseFile());
60     }
61     
62     
63     private XlsOutputHandler createTestSubject() {
64         return new XlsOutputHandler("mock", "mockPath", new Object());
65     }
66
67     @Test
68     public void testInitiate() throws Exception {
69         XlsOutputHandler testSubject;
70         Object[] title = new Object[] { null };
71         // default test
72         testSubject = createTestSubject();
73         testSubject.initiate("mock", title);
74     }
75
76     @Test
77     public void testAddRecord() throws Exception {
78         XlsOutputHandler testSubject;
79         Object[] record = new Object[] { null };
80
81         // default test
82         testSubject = createTestSubject();
83         testSubject.addRecord(record);
84     }
85 }