2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Nokia
6 * =============================================================================
7 * Modifications Copyright (C) 2019 AT&T Intellectual Property
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ============LICENSE_END=========================================================
24 package org.onap.appc.licmgr.impl;
26 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
27 import static org.mockito.BDDMockito.given;
28 import static org.mockito.BDDMockito.then;
29 import static org.mockito.Matchers.any;
30 import static org.mockito.Matchers.anyString;
32 import java.io.IOException;
33 import java.io.InputStream;
34 import javax.xml.stream.XMLInputFactory;
35 import javax.xml.stream.XMLStreamException;
36 import javax.xml.stream.XMLStreamReader;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39 import org.mockito.Mock;
40 import org.mockito.runners.MockitoJUnitRunner;
43 @RunWith(MockitoJUnitRunner.class)
44 public class XmlToLicenseModelConverterTest {
47 private XMLStreamReader xmlStreamReader;
50 private XMLInputFactory xmlInputFactory;
53 public void apply_shouldCloseXMLStreamReader_whenNoExceptionIsThrown()
54 throws XMLStreamException, IOException {
57 XmlToLicenseModelConverter converter = new XmlToLicenseModelConverter(xmlInputFactory);
58 given(xmlInputFactory.createXMLStreamReader(any(InputStream.class))).willReturn(xmlStreamReader);
61 converter.convert((a, b) -> {
62 }, anyString(), null);
65 then(xmlStreamReader).should().close();
69 public void apply_shouldCloseXMLStreamReader_whenExceptionIsThrown()
70 throws XMLStreamException {
72 XmlToLicenseModelConverter converter = new XmlToLicenseModelConverter(xmlInputFactory);
73 given(xmlInputFactory.createXMLStreamReader(any(InputStream.class))).willReturn(xmlStreamReader);
76 assertThatExceptionOfType(XMLStreamException.class)
77 .isThrownBy(() -> converter.convert((a, b) -> {
78 throw new XMLStreamException();
79 }, anyString(), null));
80 then(xmlStreamReader).should().close();