use of java.util.stream.BaseStream in project cryptomator by cryptomator.
the class AutoClosingLongStreamTest method testIntermediateOperationReturnsNewAutoClosingStream.
@Theory
public void testIntermediateOperationReturnsNewAutoClosingStream(@FromDataPoints("intermediateOperations") LongermediateOperation intermediateOperation) {
BaseStream newDelegate = (BaseStream) mock(intermediateOperation.type());
when(intermediateOperation.apply(delegate)).thenReturn(newDelegate);
BaseStream result = intermediateOperation.apply(inTest);
assertThat(result, isAutoClosing());
verifyDelegate(result, newDelegate);
}
use of java.util.stream.BaseStream in project cryptomator by cryptomator.
the class AutoClosingStreamTest method testIntermediateOperationReturnsNewAutoClosingStream.
@Theory
public void testIntermediateOperationReturnsNewAutoClosingStream(@FromDataPoints("intermediateOperations") IntermediateOperation intermediateOperation) {
BaseStream newDelegate = (BaseStream) mock(intermediateOperation.type());
when(intermediateOperation.apply(delegate)).thenReturn(newDelegate);
BaseStream result = intermediateOperation.apply(inTest);
assertThat(result, isAutoClosing());
verifyDelegate(result, newDelegate);
}
use of java.util.stream.BaseStream in project cryptomator by cryptomator.
the class AutoClosingDoubleStreamTest method testIntermediateOperationReturnsNewAutoClosingStream.
@Theory
public void testIntermediateOperationReturnsNewAutoClosingStream(@FromDataPoints("intermediateOperations") DoubleermediateOperation intermediateOperation) {
BaseStream newDelegate = (BaseStream) mock(intermediateOperation.type());
when(intermediateOperation.apply(delegate)).thenReturn(newDelegate);
BaseStream result = intermediateOperation.apply(inTest);
assertThat(result, isAutoClosing());
verifyDelegate(result, newDelegate);
}
use of java.util.stream.BaseStream in project cryptomator by cryptomator.
the class AutoClosingIntStreamTest method testIntermediateOperationReturnsNewAutoClosingStream.
@Theory
public void testIntermediateOperationReturnsNewAutoClosingStream(@FromDataPoints("intermediateOperations") IntermediateOperation intermediateOperation) {
BaseStream newDelegate = (BaseStream) mock(intermediateOperation.type());
when(intermediateOperation.apply(delegate)).thenReturn(newDelegate);
BaseStream result = intermediateOperation.apply(inTest);
assertThat(result, isAutoClosing());
verifyDelegate(result, newDelegate);
}
use of java.util.stream.BaseStream in project groovy by apache.
the class DefaultTypeTransformation method continueCastOnCollection.
private static Object continueCastOnCollection(final Object object, final Class type) {
if (object instanceof Collection && type.isAssignableFrom(LinkedHashSet.class)) {
return new LinkedHashSet((Collection) object);
}
Supplier<Collection> newCollection = () -> {
if (type.isAssignableFrom(ArrayList.class) && Modifier.isAbstract(type.getModifiers())) {
return new ArrayList();
} else if (type.isAssignableFrom(LinkedHashSet.class) && Modifier.isAbstract(type.getModifiers())) {
return new LinkedHashSet();
} else {
try {
return (Collection) type.getDeclaredConstructor().newInstance();
} catch (Exception e) {
throw new GroovyCastException("Could not instantiate instance of: " + type.getName() + ". Reason: " + e);
}
}
};
if (object instanceof BaseStream) {
Collection answer = newCollection.get();
answer.addAll(asCollection(object));
return answer;
}
if (object.getClass().isArray()) {
Collection answer = newCollection.get();
// we cannot just wrap in a List as we support primitive type arrays
int length = Array.getLength(object);
for (int i = 0; i < length; i += 1) {
answer.add(Array.get(object, i));
}
return answer;
}
return continueCastOnNumber(object, type);
}
Aggregations