From b06322787e7255973729f88479064c791bc0907e Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Sat, 18 Apr 2020 21:21:08 -0400 Subject: [PATCH] Fix RemoteFileOutboundGWTests for the proper mock --- .../RemoteFileOutboundGatewayTests.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java index a6ce6297bc..eb2a19dc55 100644 --- a/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java +++ b/spring-integration-file/src/test/java/org/springframework/integration/file/remote/gateway/RemoteFileOutboundGatewayTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.BDDMockito.willReturn; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -804,14 +805,10 @@ public class RemoteFileOutboundGatewayTests { SessionFactory sessionFactory = mock(SessionFactory.class); @SuppressWarnings("unchecked") Session session = mock(Session.class); - RemoteFileTemplate template = new RemoteFileTemplate(sessionFactory) { - - @Override - public boolean exists(String path) { - return true; - } - - }; + willReturn(Boolean.TRUE) + .given(session) + .exists(anyString()); + RemoteFileTemplate template = new RemoteFileTemplate<>(sessionFactory); template.setRemoteDirectoryExpression(new LiteralExpression("foo/")); template.setBeanFactory(mock(BeanFactory.class)); template.afterPropertiesSet(); @@ -932,7 +929,7 @@ public class RemoteFileOutboundGatewayTests { TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(template, "mput", null); assertThatIllegalStateException() .isThrownBy(() -> gw.setRemoteDirectoryExpression(new LiteralExpression("testRemoteDirectory"))) - .withMessageContaining("The 'remoteDirectoryExpression' must be set on the externally provided"); + .withMessageContaining("The 'remoteDirectoryExpression' must be set on the externally provided"); } @Test @@ -942,6 +939,7 @@ public class RemoteFileOutboundGatewayTests { Session session = mock(Session.class); TestRemoteFileOutboundGateway gw = new TestRemoteFileOutboundGateway(sessionFactory, "mput", "payload"); gw.setRemoteDirectoryExpression(new LiteralExpression("foo/")); + gw.setBeanFactory(mock(BeanFactory.class)); gw.afterPropertiesSet(); when(sessionFactory.getSession()).thenReturn(session); final AtomicReference written = new AtomicReference<>();