|
| 1 | +package com.iluwatar.abstractdocument; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import java.util.Arrays; |
| 6 | +import java.util.HashMap; |
| 7 | +import java.util.List; |
| 8 | +import java.util.Map; |
| 9 | +import java.util.stream.Stream; |
| 10 | + |
| 11 | +import static junit.framework.TestCase.assertEquals; |
| 12 | +import static junit.framework.TestCase.assertNotNull; |
| 13 | + |
| 14 | +public class AbstractDocumentTest { |
| 15 | + |
| 16 | + private static final String KEY = "key"; |
| 17 | + private static final Object VALUE = "value"; |
| 18 | + |
| 19 | + private class DocumentImplementation extends AbstractDocument { |
| 20 | + |
| 21 | + DocumentImplementation(Map<String, Object> properties) { |
| 22 | + super(properties); |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + private DocumentImplementation document = new DocumentImplementation(new HashMap<>()); |
| 27 | + |
| 28 | + @Test |
| 29 | + public void shouldPutAndGetValue() { |
| 30 | + document.put(KEY, VALUE); |
| 31 | + assertEquals(VALUE, document.get(KEY)); |
| 32 | + System.out.println(document); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void shouldRetrieveChildren() { |
| 37 | + Map<String,Object> child1 = new HashMap<>(); |
| 38 | + Map<String,Object> child2 = new HashMap<>(); |
| 39 | + List<Map<String, Object>> children = Arrays.asList(child1, child2); |
| 40 | + |
| 41 | + document.put(KEY, children); |
| 42 | + |
| 43 | + Stream<DocumentImplementation> childrenStream = document.children(KEY, DocumentImplementation::new); |
| 44 | + assertNotNull(children); |
| 45 | + assertEquals(2, childrenStream.count()); |
| 46 | + } |
| 47 | + |
| 48 | +} |
0 commit comments