Skip to content

Instantly share code, notes, and snippets.

@yevgnenll
Created May 13, 2020 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yevgnenll/212a441d7425f41a6b722b23a26192f9 to your computer and use it in GitHub Desktop.
Save yevgnenll/212a441d7425f41a6b722b23a26192f9 to your computer and use it in GitHub Desktop.
package com.geo.spatial.manager;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.Test;
import com.geo.spatial.document.info.AdministrativeAddressInfo;
public class CollectionHelperTest {
@Test
public void CollectionHelper에_collection_하위_타입을_추가하면_저장이_된다() {
Set<AdministrativeAddressInfo> testItem = new HashSet<>();
testItem.add(new AdministrativeAddressInfo());
CollectionHelper<Set<AdministrativeAddressInfo>> type = CollectionHelper.check(testItem);
assertThat(type.get().size(), is(1));
assertThat(type.get().iterator().next(), instanceOf(AdministrativeAddressInfo.class));
}
@Test
public void 비어있지_않은_collection이_반환되어야_한다() {
List<AdministrativeAddressInfo> testList = new ArrayList<>();
testList.add(new AdministrativeAddressInfo());
testList.add(new AdministrativeAddressInfo());
testList.add(new AdministrativeAddressInfo());
testList.add(new AdministrativeAddressInfo());
List<AdministrativeAddressInfo> firstEmpty = Collections.emptyList();
List<AdministrativeAddressInfo> lastEmpty = Collections.emptyList();
List<AdministrativeAddressInfo> result = (List<AdministrativeAddressInfo>) CollectionHelper.check(firstEmpty)
.isEmpty()
.thenFetch(testList)
.isEmpty()
.thenFetch(lastEmpty)
.get();
CollectionHelper<Set<AdministrativeAddressInfo>> c = CollectionHelper.check(firstEmpty)
.isEmpty()
.thenFetch(testList)
.isEmpty()
.thenFetch(lastEmpty);
Set<AdministrativeAddressInfo> r = c.get();
assertThat(result.size(), is(4));
}
@Test
public void funtion_기능을_사용하여_함수_실행을_결정한다() {
List<Integer> testList = new ArrayList() {{
add(1); add(2); add(3);
}};
List<Integer> test = (List<Integer>) CollectionHelper.check(testList)
.thenFetch(() -> sum(testList))
.isEmpty()
.thenFetch(() -> sum(testList))
.get();
test.stream()
.forEach(item -> assertTrue(item / 1000 > 0));
}
private List<Integer> sum(List<Integer> list) {
return list.stream()
.map((item) -> item + 1000)
.collect(Collectors.toList());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment