2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.spi.source;
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;
15 import java.util.Optional;
16 import org.junit.Before;
17 import org.junit.Test;
19 public class SourceExceptionTest {
20 private StatementSourceReference mock;
23 public void before() {
24 mock = mock(StatementSourceReference.class);
25 doReturn("mock").when(mock).toString();
29 public void testThrowIfFalse() {
30 SourceException.throwIf(false, mock, "");
33 @Test(expected = NullPointerException.class)
34 public void testThrowIfTrueMockNull() {
35 SourceException.throwIf(true, mock, null);
38 @Test(expected = SourceException.class)
39 public void testThrowIfTrueMockEmpty() {
40 SourceException.throwIf(true, mock, "");
43 @Test(expected = NullPointerException.class)
44 public void testThrowIfNullNullMockNull() {
45 SourceException.throwIfNull(null, mock, null);
48 @Test(expected = SourceException.class)
49 public void testThrowIfNullNullMockEmpty() {
50 SourceException.throwIfNull(null, mock, "");
54 public void testThrowIfNullMock() {
55 assertSame(mock, SourceException.throwIfNull(mock, mock, ""));
59 public void testUnwrapPresent() {
60 assertEquals("test", SourceException.unwrap(Optional.of("test"), mock, ""));
63 @Test(expected = SourceException.class)
64 public void testUnwrapAbsent() {
65 SourceException.unwrap(Optional.empty(), mock, "");