package com.humaorie.dollar;
import com.humaorie.dollar.ArrayWrapper.IntegerArrayWrapper;
import java.util.Iterator;
import org.junit.Assert;
import org.junit.Test;
public class LazyMappedWrapperTest {
public static class IntegerToString implements Dollar.Function<String, Integer> {
@Override
public String call(Integer object) {
return object.toString();
}
}
@Test(expected = IllegalArgumentException.class)
public void delegateMustBeNonNull() {
new LazyMappedWrapper<String, Integer>(null, new IntegerToString());
}
@Test(expected = IllegalArgumentException.class)
public void mapperMustBeNonNull() {
new LazyMappedWrapper<String, Integer>(new RangeWrapper(1), null);
}
@Test
public void appliesMapperToEveryElementProvidedByDelegate() {
LazyMappedWrapper<String, Integer> wrapper = new LazyMappedWrapper<String, Integer>(new IntegerArrayWrapper(new int[]{1}), new IntegerToString());
Iterator<String> iterator = wrapper.iterator();
Assert.assertEquals("1", iterator.next());
}
}