Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-parser-spi / src / test / java / org / opendaylight / yangtools / yang / parser / spi / source / SourceExceptionTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.parser.spi.source;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertSame;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14
15 import java.util.Optional;
16 import org.junit.Before;
17 import org.junit.Test;
18
19 public class SourceExceptionTest {
20     private StatementSourceReference mock;
21
22     @Before
23     public void before() {
24         mock = mock(StatementSourceReference.class);
25         doReturn("mock").when(mock).toString();
26     }
27
28     @Test
29     public void testThrowIfFalse() {
30         SourceException.throwIf(false, mock, "");
31     }
32
33     @Test(expected = NullPointerException.class)
34     public void testThrowIfTrueMockNull() {
35         SourceException.throwIf(true, mock, null);
36     }
37
38     @Test(expected = SourceException.class)
39     public void testThrowIfTrueMockEmpty() {
40         SourceException.throwIf(true, mock, "");
41     }
42
43     @Test(expected = NullPointerException.class)
44     public void testThrowIfNullNullMockNull() {
45         SourceException.throwIfNull(null, mock, null);
46     }
47
48     @Test(expected = SourceException.class)
49     public void testThrowIfNullNullMockEmpty() {
50         SourceException.throwIfNull(null, mock, "");
51     }
52
53     @Test
54     public void testThrowIfNullMock() {
55         assertSame(mock, SourceException.throwIfNull(mock, mock, ""));
56     }
57
58     @Test
59     public void testUnwrapPresent() {
60         assertEquals("test", SourceException.unwrap(Optional.of("test"), mock, ""));
61     }
62
63     @Test(expected = SourceException.class)
64     public void testUnwrapAbsent() {
65         SourceException.unwrap(Optional.empty(), mock, "");
66     }
67 }