View Javadoc
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      private void assertCorrect(final String assertMessage, final NotImplementedException nie, final String message, final Throwable nested, final String code) {
31          assertNotNull(nie, assertMessage + ": target is null");
32          assertEquals(message, nie.getMessage(), assertMessage + ": Message not equal");
33          assertEquals(nested, nie.getCause(), assertMessage + ": Nested throwable not equal");
34          assertEquals(code, nie.getCode(), assertMessage + ": Code not equal");
35      }
36  
37      @Test
38      public void testConstructors() {
39          final Throwable nested = new RuntimeException();
40          final String message = "Not Implemented";
41          final String code = "CODE";
42  
43          NotImplementedException nie = new NotImplementedException(message);
44          assertCorrect("Issue in (String)", nie, message, null, null);
45          nie = new NotImplementedException(nested);
46          assertCorrect("Issue in (Throwable)", nie, nested.toString(), nested, null);
47          nie = new NotImplementedException(message, nested);
48          assertCorrect("Issue in (String, Throwable)", nie, message, nested, null);
49          nie = new NotImplementedException(message, code);
50          assertCorrect("Issue in (String, String)", nie, message, null, code);
51          nie = new NotImplementedException(nested, code);
52          assertCorrect("Issue in (Throwable, String)", nie, nested.toString(), nested, code);
53          nie = new NotImplementedException(message, nested, code);
54          assertCorrect("Issue in (String, Throwable, String)", nie, message, nested, code);
55  
56          assertNull(new NotImplementedException().getCode());
57      }
58  }