| 1 | package ezvcard.util; |
| 2 | |
| 3 | import static org.mockito.Mockito.doThrow; |
| 4 | import static org.mockito.Mockito.mock; |
| 5 | import static org.mockito.Mockito.verify; |
| 6 | |
| 7 | import java.io.Closeable; |
| 8 | import java.io.IOException; |
| 9 | |
| 10 | import org.junit.Test; |
| 11 | |
| 12 | /* |
| 13 | Copyright (c) 2012-2023, Michael Angstadt |
| 14 | All rights reserved. |
| 15 | |
| 16 | Redistribution and use in source and binary forms, with or without |
| 17 | modification, are permitted provided that the following conditions are met: |
| 18 | |
| 19 | 1. Redistributions of source code must retain the above copyright notice, this |
| 20 | list of conditions and the following disclaimer. |
| 21 | 2. Redistributions in binary form must reproduce the above copyright notice, |
| 22 | this list of conditions and the following disclaimer in the documentation |
| 23 | and/or other materials provided with the distribution. |
| 24 | |
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 26 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 27 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 29 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 30 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 32 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 33 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | /** |
| 38 | * @author Michael Angstadt |
| 39 | */ |
| 40 | public class IOUtilsTest { |
| 41 | @Test |
| 42 | public void closeQuietly() throws Exception { |
| 43 | IOUtils.closeQuietly(null); |
| 44 | |
| 45 | Closeable closeable = mock(Closeable.class); |
| 46 | IOUtils.closeQuietly(closeable); |
| 47 | verify(closeable).close(); |
| 48 | |
| 49 | closeable = mock(Closeable.class); |
| 50 | doThrow(new IOException()).when(closeable).close(); |
| 51 | IOUtils.closeQuietly(closeable); |
| 52 | verify(closeable).close(); |
| 53 | } |
| 54 | } |