2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.openecomp.sdc.asdctool.migration.tasks.handlers;
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;
30 import java.io.FileOutputStream;
31 import java.io.IOException;
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.*;
38 @RunWith(MockitoJUnitRunner.class)
39 public class XlsOutputHandlerTest {
42 private XlsOutputHandler handler = new XlsOutputHandler(null, "mock");
45 private Workbook workbook;
47 private FileOutputStream xlsFile;
50 public void verifyThatFileIsNotCreatedIfNoRecordsAdded() throws IOException {
51 assertFalse(handler.writeOutputAndCloseFile());
52 verify(workbook, times(0)).write(any());
56 public void verifyThatFileIsCreatedIfSomeRecordsAdded() throws IOException {
57 handler.addRecord("mock");
58 doReturn(xlsFile).when(handler).getXlsFile();
59 assertTrue(handler.writeOutputAndCloseFile());
63 private XlsOutputHandler createTestSubject() {
64 return new XlsOutputHandler("mock", "mockPath", new Object());
68 public void testInitiate() throws Exception {
69 XlsOutputHandler testSubject;
70 Object[] title = new Object[] { null };
72 testSubject = createTestSubject();
73 testSubject.initiate("mock", title);
77 public void testAddRecord() throws Exception {
78 XlsOutputHandler testSubject;
79 Object[] record = new Object[] { null };
82 testSubject = createTestSubject();
83 testSubject.addRecord(record);