FtpFileMover implements FileMoverStrategy { public void connect(WctDepositParameter depositParameter) { try { this.ftpClient = ftpClientFactory.createInstance(); ftpClient.connect(depositParameter.getFtpHost()); ftpClient.user(depositParameter.getFtpUserName()); ftpClient.pass(depositParameter.getFtpPassword()); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); } catch (IOException ioe) { throw new RuntimeException("Failed to open connection to FTP server: " + depositParameter.getFtpHost(), ioe); } } @Inject  FtpFileMover(FtpClientFactory ftpClientFactory); void connect(WctDepositParameter depositParameter); void createAndChangeToDirectory(String depositDirectory); void changeToDirectory(String depositDirectory); void storeFile(String fileName, InputStream stream); void close();  }
@Test public void test_connect() throws IOException { Mockery mockContext = constructMockContext(); final FTPClient mockedFtpClient = mockContext.mock(FTPClient.class); final FtpClientFactory mockedFactory = mockContext.mock(FtpClientFactory.class); mockContext.checking(new Expectations() { { one(mockedFactory).createInstance(); will(returnValue(mockedFtpClient)); one(mockedFtpClient).connect(with(any(String.class))); one(mockedFtpClient).user(with(any(String.class))); will(returnValue(1)); one(mockedFtpClient).pass(with(any(String.class))); one(mockedFtpClient).setFileType(FTP.BINARY_FILE_TYPE); } }); WctDepositParameter depositParameter = new WctDepositParameter(); FtpFileMover ftpFileMover = new FtpFileMover(mockedFactory); ftpFileMover.connect(depositParameter); mockContext.assertIsSatisfied(); }