Skip to content

Instantly share code, notes, and snippets.

@Charnnarong
Created May 2, 2020 11:34
Show Gist options
  • Save Charnnarong/17152e73f8c4888e3cff8d77f56b5f31 to your computer and use it in GitHub Desktop.
Save Charnnarong/17152e73f8c4888e3cff8d77f56b5f31 to your computer and use it in GitHub Desktop.
import com.xxx.yyy.zzz.NestedMapBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.util.Map;
public class NestedMapBuilderTest {
@Test
public void testEmptyMap() {
var input = Map.of();
var expected = Map.of();
var result = NestedMapBuilder.create(input);
Assertions.assertEquals(expected, result);
}
@Test
public void testAddSimpleMap() {
var input = Map.of("hello", "test");
var expected = Map.of("hello", "test");
var result = NestedMapBuilder.create(input);
Assertions.assertEquals(expected, result);
}
@Test
public void testAddTwoNestedMap() {
var input = Map.of("hello.test", 1);
var expected = Map.of("hello", Map.of("test", 1));
var result = NestedMapBuilder.create(input);
Assertions.assertEquals(expected, result);
}
@Test
public void testAddThreeNestedMap() {
var input = Map.of("hello.test.hello", 1);
var expected = Map.of("hello", Map.of("test", Map.of("hello", 1)));
var result = NestedMapBuilder.create(input);
Assertions.assertEquals(expected, result);
}
@Test
public void testAddFourNestedMap() {
var input = Map.of("hello.test.hello.cool", 1);
var expected = Map.of("hello", Map.of("test", Map.of("hello", Map.of("cool", 1))));
var result = NestedMapBuilder.create(input);
Assertions.assertEquals(expected, result);
}
@Test
public void testAddFiveNestedMap() {
var input = Map.of("hello.test.hello.cool.really", "XXXX");
var expected = Map.of("hello", Map.of("test", Map.of("hello", Map.of("cool", Map.of("really", "XXXX")))));
var result = NestedMapBuilder.create(input);
Assertions.assertEquals(expected, result);
}
@Test
public void testAddSixNestedMap() {
var input = Map.of("hello.test.hello.cool.really.deep", "XXXX");
var expected = Map.of("hello", Map.of("test", Map.of("hello", Map.of("cool", Map.of("really", Map.of("deep","XXXX"))))));
var result = NestedMapBuilder.create(input);
Assertions.assertEquals(expected, result);
}
}
//--------------------
public class NestedMapBuilder {
public static <k, v> Map<k, v> create(Map<k, v> map) {
return map;
}
}
@Charnnarong
Copy link
Author

Imgur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment