• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements.  See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License.  You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 package org.apache.commons.lang3;
18 
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertNotNull;
21 import static org.junit.jupiter.api.Assertions.assertNull;
22 
23 import org.junit.jupiter.api.Test;
24 
25 /**
26  * Unit tests {@link org.apache.commons.lang3.NotImplementedException}.
27  */
28 public class NotImplementedExceptionTest extends AbstractLangTest {
29 
30     @Test
testConstructors()31     public void testConstructors() {
32         final Throwable nested = new RuntimeException();
33         final String message = "Not Implemented";
34         final String code = "CODE";
35 
36         NotImplementedException nie = new NotImplementedException(message);
37         assertCorrect("Issue in (String)", nie, message, null, null);
38         nie = new NotImplementedException(nested);
39         assertCorrect("Issue in (Throwable)", nie, nested.toString(), nested, null);
40         nie = new NotImplementedException(message, nested);
41         assertCorrect("Issue in (String, Throwable)", nie, message, nested, null);
42         nie = new NotImplementedException(message, code);
43         assertCorrect("Issue in (String, String)", nie, message, null, code);
44         nie = new NotImplementedException(nested, code);
45         assertCorrect("Issue in (Throwable, String)", nie, nested.toString(), nested, code);
46         nie = new NotImplementedException(message, nested, code);
47         assertCorrect("Issue in (String, Throwable, String)", nie, message, nested, code);
48 
49         assertNull(new NotImplementedException().getCode());
50     }
51 
assertCorrect(final String assertMessage, final NotImplementedException nie, final String message, final Throwable nested, final String code)52     private void assertCorrect(final String assertMessage, final NotImplementedException nie, final String message, final Throwable nested, final String code) {
53         assertNotNull(nie, assertMessage + ": target is null");
54         assertEquals(message, nie.getMessage(), assertMessage + ": Message not equal");
55         assertEquals(nested, nie.getCause(), assertMessage + ": Nested throwable not equal");
56         assertEquals(code, nie.getCode(), assertMessage + ": Code not equal");
57     }
58 }
59