Sonar fixes according latest report (#2676)

* Sonar fixes according latest report

* Fix initialization order in the `GatewayMethodInboundMessageMapper`

* Fix mock in the `DelegatingSessionFactoryTests`

* Fix `AbstractRemoteFileOutboundGateway.listFilesInRemoteDir`

* * PR comments

* * Fix `AbstractRemoteFileOutboundGateway.listFilesInRemoteDir` complexity
This commit is contained in:
Artem Bilan
2018-12-22 11:57:35 -05:00
committed by Gary Russell
parent 1943c15afe
commit 81b4ea1bef
9 changed files with 207 additions and 157 deletions

View File

@@ -421,13 +421,12 @@ public class RemoteFileOutboundGatewayTests {
@SuppressWarnings("unchecked")
MessageBuilder<List<TestLsEntry>> out = (MessageBuilder<List<TestLsEntry>>) gw
.handleRequestMessage(new GenericMessage<>("testremote/x"));
assertEquals(6, out.getPayload().size());
assertEquals(5, out.getPayload().size());
assertEquals("f1", out.getPayload().get(0).getFilename());
assertEquals("d1", out.getPayload().get(1).getFilename());
assertEquals("d1/d2", out.getPayload().get(2).getFilename());
assertEquals("d1/d2/f4", out.getPayload().get(3).getFilename());
assertEquals("d1/f3", out.getPayload().get(4).getFilename());
assertEquals("f2", out.getPayload().get(5).getFilename());
assertEquals("d1/f3", out.getPayload().get(3).getFilename());
assertEquals("f2", out.getPayload().get(4).getFilename());
assertEquals("testremote/x/",
out.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-2018 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.
@@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -50,6 +52,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 4.2
*
*/
@@ -94,7 +98,9 @@ public class DelegatingSessionFactoryTests {
@Test
public void testFlow() throws Exception {
in.send(new GenericMessage<String>("foo"));
given(foo.mockSession.list(anyString()))
.willReturn(new String[0]);
in.send(new GenericMessage<>("foo"));
Message<?> received = out.receive(0);
assertNotNull(received);
verify(foo.mockSession).list("foo/");
@@ -102,7 +108,8 @@ public class DelegatingSessionFactoryTests {
}
@Configuration
@ImportResource("classpath:/org/springframework/integration/file/remote/session/delegating-session-factory-context.xml")
@ImportResource(
"classpath:/org/springframework/integration/file/remote/session/delegating-session-factory-context.xml")
@EnableIntegration
public static class Config {
@@ -119,59 +126,59 @@ public class DelegatingSessionFactoryTests {
@Bean
DelegatingSessionFactory<String> dsf() {
SessionFactoryLocator<String> sff = sessionFactoryLocator();
return new DelegatingSessionFactory<String>(sff);
return new DelegatingSessionFactory<>(sff);
}
@Bean
public SessionFactoryLocator<String> sessionFactoryLocator() {
Map<Object, SessionFactory<String>> factories = new HashMap<Object, SessionFactory<String>>();
Map<Object, SessionFactory<String>> factories = new HashMap<>();
factories.put("foo", foo());
TestSessionFactory bar = bar();
factories.put("bar", bar);
SessionFactoryLocator<String> sff = new DefaultSessionFactoryLocator<String>(factories, bar);
return sff;
return new DefaultSessionFactoryLocator<>(factories, bar);
}
@ServiceActivator(inputChannel = "c1")
@Bean
MessageHandler handler() {
AbstractRemoteFileOutboundGateway<String> gateway = new AbstractRemoteFileOutboundGateway<String>(dsf(), "ls", "payload") {
AbstractRemoteFileOutboundGateway<String> gateway =
new AbstractRemoteFileOutboundGateway<String>(dsf(), "ls", "payload") {
@Override
protected boolean isDirectory(String file) {
return false;
}
@Override
protected boolean isDirectory(String file) {
return false;
}
@Override
protected boolean isLink(String file) {
return false;
}
@Override
protected boolean isLink(String file) {
return false;
}
@Override
protected String getFilename(String file) {
return file;
}
@Override
protected String getFilename(String file) {
return file;
}
@Override
protected String getFilename(AbstractFileInfo<String> file) {
return file.getFilename();
}
@Override
protected String getFilename(AbstractFileInfo<String> file) {
return file.getFilename();
}
@Override
protected long getModified(String file) {
return 0;
}
@Override
protected long getModified(String file) {
return 0;
}
@Override
protected List<AbstractFileInfo<String>> asFileInfoList(Collection<String> files) {
return null;
}
@Override
protected List<AbstractFileInfo<String>> asFileInfoList(Collection<String> files) {
return null;
}
@Override
protected String enhanceNameWithSubDirectory(String file, String directory) {
return null;
}
};
@Override
protected String enhanceNameWithSubDirectory(String file, String directory) {
return null;
}
};
gateway.setOutputChannelName("c2");
gateway.setOptions("-1");
return gateway;