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  
18  package org.apache.commons.cli;
19  
20  import static org.junit.jupiter.api.Assertions.assertEquals;
21  
22  import org.junit.jupiter.api.Test;
23  
24  public class DeprecatedAttributesTest {
25  
26      @Test
27      public void testBuilderNonDefaults() {
28          // @formatter:off
29          final DeprecatedAttributes value = DeprecatedAttributes.builder()
30                  .setDescription("Use Bar instead!")
31                  .setForRemoval(true)
32                  .setSince("2.0")
33                  .get();
34          // @formatter:on
35          assertEquals("Use Bar instead!", value.getDescription());
36          assertEquals("2.0", value.getSince());
37          assertEquals(true, value.isForRemoval());
38      }
39  
40      @Test
41      public void testBuilderNonDefaultsToString() {
42          // @formatter:off
43          assertEquals("Deprecated for removal since 2.0: Use Bar instead!", DeprecatedAttributes.builder()
44                  .setDescription("Use Bar instead!")
45                  .setForRemoval(true)
46                  .setSince("2.0")
47                  .get().toString());
48          assertEquals("Deprecated for removal: Use Bar instead!", DeprecatedAttributes.builder()
49                  .setDescription("Use Bar instead!")
50                  .setForRemoval(true)
51                  .get().toString());
52          assertEquals("Deprecated since 2.0: Use Bar instead!",
53                  DeprecatedAttributes.builder()
54                  .setDescription("Use Bar instead!")
55                  .setSince("2.0")
56                  .get().toString());
57          assertEquals("Deprecated: Use Bar instead!", DeprecatedAttributes.builder()
58                  .setDescription("Use Bar instead!")
59                  .get().toString());
60          // @formatter:on
61      }
62  
63      @Test
64      public void testDefaultBuilder() {
65          final DeprecatedAttributes defaultValue = DeprecatedAttributes.builder().get();
66          assertEquals(DeprecatedAttributes.DEFAULT.getDescription(), defaultValue.getDescription());
67          assertEquals(DeprecatedAttributes.DEFAULT.getSince(), defaultValue.getSince());
68          assertEquals(DeprecatedAttributes.DEFAULT.isForRemoval(), defaultValue.isForRemoval());
69      }
70  
71      @Test
72      public void testDefaultToString() {
73          assertEquals("Deprecated", DeprecatedAttributes.DEFAULT.toString());
74      }
75  }