Example usage for org.apache.commons.io.input BrokenInputStream BrokenInputStream

List of usage examples for org.apache.commons.io.input BrokenInputStream BrokenInputStream

Introduction

In this page you can find the example usage for org.apache.commons.io.input BrokenInputStream BrokenInputStream.

Prototype

public BrokenInputStream(IOException exception) 

Source Link

Document

Creates a new stream that always throws the given exception.

Usage

From source file:com.joyent.manta.client.multipart.EncryptingPartEntityTest.java

public void doesNotCloseSuppliedOutputStreamWhenWrittenSuccessfully() throws Exception {
    final EncryptingPartEntity encryptingPartEntity = new EncryptingPartEntity(state.getCipherStream(),
            state.getMultipartStream(),//from   w ww .j  a v  a  2  s  .c om
            new InputStreamEntity(new BrokenInputStream(new IOException("bad input"))), CALLBACK_NOOP);

    final OutputStream output = Mockito.mock(OutputStream.class);
    Assert.assertThrows(IOException.class, () -> encryptingPartEntity.writeTo(output));
    Mockito.verify(output, Mockito.never()).close();
}

From source file:com.joyent.manta.client.crypto.EncryptingEntityTest.java

public void doesNotCloseSuppliedOutputStreamWhenFailureOccurs() throws Exception {
    final SupportedCipherDetails cipherDetails = DefaultsConfigContext.DEFAULT_CIPHER;
    final SecretKey secretKey = SecretKeyUtils.generate(cipherDetails);
    final EncryptingEntity encryptingEntity = new EncryptingEntity(secretKey, cipherDetails,
            new InputStreamEntity(new BrokenInputStream(new IOException("bad input"))));

    final OutputStream output = Mockito.mock(OutputStream.class);
    Assert.assertThrows(IOException.class, () -> encryptingEntity.writeTo(output));
    Mockito.verify(output, Mockito.never()).close();
}