1+ /*
2+ * Copyright (c) 2024 Oracle and/or its affiliates.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+ package io .helidon .build .cli .harness ;
17+
18+ import org .junit .jupiter .api .Test ;
19+
20+ import java .util .LinkedHashMap ;
21+ import java .util .Map ;
22+
23+ import static org .hamcrest .CoreMatchers .is ;
24+ import static org .hamcrest .MatcherAssert .assertThat ;
25+
26+ class OutputHelperTest {
27+
28+ @ Test
29+ void testTable () {
30+ Map <String , String > map = new LinkedHashMap <>();
31+ map .put ("key1" , "value1" );
32+ map .put ("key2" , "value2" );
33+ String expected = " key1 value1\n key2 value2" ;
34+ assertThat (OutputHelper .table (map ), is (expected ));
35+ }
36+
37+ @ Test
38+ void testTableWithMaxKeyWidth () {
39+ Map <String , String > map = new LinkedHashMap <>();
40+ map .put ("key1" , "value1" );
41+ map .put ("key2" , "value2" );
42+ String expected = " key1 value1\n key2 value2" ;
43+ assertThat (OutputHelper .table (map , 4 ), is (expected ));
44+ }
45+
46+ @ Test
47+ void testMaxKeyWidth () {
48+ Map <String , String > map1 = new LinkedHashMap <>();
49+ map1 .put ("key1" , "value1" );
50+ map1 .put ("longerKey" , "value2" );
51+ Map <String , String > map2 = new LinkedHashMap <>();
52+ map2 .put ("short" , "value3" );
53+ map2 .put ("longestKey" , "value4" );
54+ int expected = 10 ; // length of "longestKey"
55+ assertThat (OutputHelper .maxKeyWidth (map1 , map2 ), is (expected ));
56+ }
57+ }
0 commit comments