Skip to content

Commit

Permalink
Update OutputHelperTest to use LinkedHashMap for predictable order
Browse files Browse the repository at this point in the history
  • Loading branch information
abdelhak-zaaim committed Nov 6, 2024
1 parent 0c2a1ae commit 1fac01d
Showing 1 changed file with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.junit.jupiter.api.Test;

import java.util.LinkedHashMap;
import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -26,34 +27,30 @@ class OutputHelperTest {

@Test
void testTable() {
Map<String, String> map = Map.of(
"key1", "value1",
"key2", "value2"
);
Map<String, String> map = new LinkedHashMap<>();
map.put("key1", "value1");
map.put("key2", "value2");
String expected = " key1 value1\n key2 value2";
assertThat(OutputHelper.table(map), is(expected));
}

@Test
void testTableWithMaxKeyWidth() {
Map<String, String> map = Map.of(
"key1", "value1",
"key2", "value2"
);
Map<String, String> map = new LinkedHashMap<>();
map.put("key1", "value1");
map.put("key2", "value2");
String expected = " key1 value1\n key2 value2";
assertThat(OutputHelper.table(map, 4), is(expected));
}

@Test
void testMaxKeyWidth() {
Map<String, String> map1 = Map.of(
"key1", "value1",
"longerKey", "value2"
);
Map<String, String> map2 = Map.of(
"short", "value3",
"longestKey", "value4"
);
Map<String, String> map1 = new LinkedHashMap<>();
map1.put("key1", "value1");
map1.put("longerKey", "value2");
Map<String, String> map2 = new LinkedHashMap<>();
map2.put("short", "value3");
map2.put("longestKey", "value4");
int expected = 10; // length of "longestKey"
assertThat(OutputHelper.maxKeyWidth(map1, map2), is(expected));
}
Expand Down

0 comments on commit 1fac01d

Please sign in to comment.