2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2018 Nokia
 
   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.
 
  19  * ============LICENSE_END=========================================================
 
  22 package org.onap.appc.licmgr.impl;
 
  24 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
 
  25 import static org.mockito.BDDMockito.given;
 
  26 import static org.mockito.BDDMockito.then;
 
  27 import static org.mockito.Matchers.any;
 
  28 import static org.mockito.Matchers.anyString;
 
  30 import java.io.IOException;
 
  31 import java.io.InputStream;
 
  32 import javax.xml.stream.XMLInputFactory;
 
  33 import javax.xml.stream.XMLStreamException;
 
  34 import javax.xml.stream.XMLStreamReader;
 
  35 import org.junit.Test;
 
  36 import org.junit.runner.RunWith;
 
  37 import org.mockito.Mock;
 
  38 import org.mockito.runners.MockitoJUnitRunner;
 
  41 @RunWith(MockitoJUnitRunner.class)
 
  42 public class XmlToLicenseModelConverterTest {
 
  45     private XMLStreamReader xmlStreamReader;
 
  48     private XMLInputFactory xmlInputFactory;
 
  51     public void apply_shouldCloseXMLStreamReader_whenNoExceptionIsThrown()
 
  52         throws XMLStreamException, IOException {
 
  55         XmlToLicenseModelConverter converter = new XmlToLicenseModelConverter(xmlInputFactory);
 
  56         given(xmlInputFactory.createXMLStreamReader(any(InputStream.class))).willReturn(xmlStreamReader);
 
  59         converter.convert((a, b) -> {
 
  60         }, anyString(), null);
 
  63         then(xmlStreamReader).should().close();
 
  67     public void apply_shouldCloseXMLStreamReader_whenExceptionIsThrown()
 
  68         throws XMLStreamException {
 
  70         XmlToLicenseModelConverter converter = new XmlToLicenseModelConverter(xmlInputFactory);
 
  71         given(xmlInputFactory.createXMLStreamReader(any(InputStream.class))).willReturn(xmlStreamReader);
 
  74         assertThatExceptionOfType(XMLStreamException.class)
 
  75             .isThrownBy(() -> converter.convert((a, b) -> {
 
  76                 throw new XMLStreamException();
 
  77             }, anyString(), null));
 
  78         then(xmlStreamReader).should().close();