Search in sources :

Example 1 with BaseStream

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);
}
Also used : BaseStream(java.util.stream.BaseStream) Theory(org.junit.experimental.theories.Theory)

Example 2 with BaseStream

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);
}
Also used : BaseStream(java.util.stream.BaseStream) Theory(org.junit.experimental.theories.Theory)

Example 3 with BaseStream

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);
}
Also used : BaseStream(java.util.stream.BaseStream) Theory(org.junit.experimental.theories.Theory)

Example 4 with BaseStream

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);
}
Also used : BaseStream(java.util.stream.BaseStream) Theory(org.junit.experimental.theories.Theory)

Example 5 with BaseStream

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);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BaseStream(java.util.stream.BaseStream) ArrayList(java.util.ArrayList) Collection(java.util.Collection) InvokerInvocationException(org.codehaus.groovy.runtime.InvokerInvocationException) GroovyRuntimeException(groovy.lang.GroovyRuntimeException) IOException(java.io.IOException)

Aggregations

BaseStream (java.util.stream.BaseStream)5 Theory (org.junit.experimental.theories.Theory)4 GroovyRuntimeException (groovy.lang.GroovyRuntimeException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 InvokerInvocationException (org.codehaus.groovy.runtime.InvokerInvocationException)1