RemoteFileTemplate: Improve test coverage
This commit is contained in:
@@ -17,12 +17,15 @@
|
||||
package org.springframework.integration.file.remote;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -30,17 +33,18 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.jgroups.util.UUID;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.integration.file.remote.session.Session;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
import org.springframework.integration.file.support.FileExistsMode;
|
||||
import org.springframework.messaging.MessageDeliveryException;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
@@ -125,9 +129,36 @@ public class RemoteFileTemplateTests {
|
||||
@Test
|
||||
public void testStream() throws IOException {
|
||||
ByteArrayInputStream stream = new ByteArrayInputStream("foo".getBytes());
|
||||
this.template.send(new GenericMessage<InputStream>(stream),
|
||||
this.template.send(new GenericMessage<>(stream),
|
||||
FileExistsMode.IGNORE);
|
||||
verify(this.session).write(Mockito.eq(stream), Mockito.any());
|
||||
verify(this.session).write(eq(stream), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testString() throws IOException {
|
||||
this.template.send(new GenericMessage<>("foo"), FileExistsMode.IGNORE);
|
||||
verify(this.session).write(any(InputStream.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBytes() throws IOException {
|
||||
this.template.send(new GenericMessage<>("foo".getBytes()), FileExistsMode.IGNORE);
|
||||
verify(this.session).write(any(InputStream.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingFile() {
|
||||
this.template.send(new GenericMessage<>(new File(UUID.randomUUID().toString())), FileExistsMode.IGNORE);
|
||||
verifyNoMoreInteractions(this.session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalid() {
|
||||
assertThatThrownBy(() -> this.template
|
||||
.send(new GenericMessage<>(new Object()), FileExistsMode.IGNORE))
|
||||
.isInstanceOf(MessageDeliveryException.class)
|
||||
.hasCauseInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("Unsupported payload type");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user