Skip to content

Commit 0259d08

Browse files
committed
RemoteFileTemplate: Improve test coverage
1 parent d2eee91 commit 0259d08

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

spring-integration-file/src/test/java/org/springframework/integration/file/remote/RemoteFileTemplateTests.java

+34-3
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,34 @@
1717
package org.springframework.integration.file.remote;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2021
import static org.assertj.core.api.Assertions.fail;
2122
import static org.mockito.ArgumentMatchers.any;
2223
import static org.mockito.ArgumentMatchers.anyString;
24+
import static org.mockito.ArgumentMatchers.eq;
2325
import static org.mockito.Mockito.mock;
2426
import static org.mockito.Mockito.never;
2527
import static org.mockito.Mockito.verify;
28+
import static org.mockito.Mockito.verifyNoMoreInteractions;
2629
import static org.mockito.Mockito.when;
2730

2831
import java.io.ByteArrayInputStream;
2932
import java.io.File;
3033
import java.io.IOException;
3134
import java.io.InputStream;
3235

36+
import org.jgroups.util.UUID;
3337
import org.junit.Before;
3438
import org.junit.Rule;
3539
import org.junit.Test;
3640
import org.junit.rules.TemporaryFolder;
37-
import org.mockito.Mockito;
3841

3942
import org.springframework.beans.factory.BeanFactory;
4043
import org.springframework.expression.common.LiteralExpression;
4144
import org.springframework.integration.file.remote.session.Session;
4245
import org.springframework.integration.file.remote.session.SessionFactory;
4346
import org.springframework.integration.file.support.FileExistsMode;
47+
import org.springframework.messaging.MessageDeliveryException;
4448
import org.springframework.messaging.MessagingException;
4549
import org.springframework.messaging.support.GenericMessage;
4650

@@ -125,9 +129,36 @@ public void testIgnoreNotExists() throws Exception {
125129
@Test
126130
public void testStream() throws IOException {
127131
ByteArrayInputStream stream = new ByteArrayInputStream("foo".getBytes());
128-
this.template.send(new GenericMessage<InputStream>(stream),
132+
this.template.send(new GenericMessage<>(stream),
129133
FileExistsMode.IGNORE);
130-
verify(this.session).write(Mockito.eq(stream), Mockito.any());
134+
verify(this.session).write(eq(stream), any());
135+
}
136+
137+
@Test
138+
public void testString() throws IOException {
139+
this.template.send(new GenericMessage<>("foo"), FileExistsMode.IGNORE);
140+
verify(this.session).write(any(InputStream.class), any());
141+
}
142+
143+
@Test
144+
public void testBytes() throws IOException {
145+
this.template.send(new GenericMessage<>("foo".getBytes()), FileExistsMode.IGNORE);
146+
verify(this.session).write(any(InputStream.class), any());
147+
}
148+
149+
@Test
150+
public void testMissingFile() {
151+
this.template.send(new GenericMessage<>(new File(UUID.randomUUID().toString())), FileExistsMode.IGNORE);
152+
verifyNoMoreInteractions(this.session);
153+
}
154+
155+
@Test
156+
public void testInvalid() {
157+
assertThatThrownBy(() -> this.template
158+
.send(new GenericMessage<>(new Object()), FileExistsMode.IGNORE))
159+
.isInstanceOf(MessageDeliveryException.class)
160+
.hasCauseInstanceOf(IllegalArgumentException.class)
161+
.hasMessageContaining("Unsupported payload type");
131162
}
132163

133164
}

0 commit comments

Comments
 (0)