Java Code Examples for org.jmock.Mockery#assertIsSatisfied()
The following examples show how to use
org.jmock.Mockery#assertIsSatisfied() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FtpFileMoverTest.java From webcurator with Apache License 2.0 | 6 votes |
@Test(expected = RuntimeException.class) public void test_calling_create_And_Change_To_Directory_when_not_connected() 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)); } }); FtpFileMover ftpFileMover = new FtpFileMover(mockedFactory); ftpFileMover.createAndChangeToDirectory("directory"); mockContext.assertIsSatisfied(); }
Example 2
Source File: FileMoverTest.java From webcurator with Apache License 2.0 | 6 votes |
@Test public void test_moving_file_to_server() throws IOException { Mockery mockContext = new Mockery(); final FileMoverStrategy mockedFileMoverStrategy = mockContext.mock(FileMoverStrategy.class); final WctDepositParameter depositParameter = new WctDepositParameter(); createExpectations(mockContext, mockedFileMoverStrategy, depositParameter); List<ArchiveFile> files = populateListWithOneArchiveFile(); FileMover fileMover = new FileMoverImpl(mockedFileMoverStrategy); MetsDocument metsDoc = new MetsDocument("mets.xml", "the xml"); fileMover.move(metsDoc, files, depositParameter); assertThat(metsDoc.getDepositDirectoryName(), containsString("deposit")); mockContext.assertIsSatisfied(); }
Example 3
Source File: AlarmMockTest.java From androidtestdebug with MIT License | 6 votes |
@SuppressWarnings("deprecation") @Test public void 使用模拟IGetDate对象测试() throws InterruptedException { Option option = new Option(); option.alarmTime = new Date(1, 12, 15, 16, 15, 0); option.repeatSetting = RepeatSetting.EveryDay; Mockery context = new Mockery(); final IGetDate gd = context.mock(IGetDate.class); context.checking(new Expectations() {{ atLeast(1).of(gd).Now(); will(returnValue(new Date(1, 12, 15, 16, 15, 0))); }}); TestableAlarm alarm = new TestableAlarm(option, gd); alarm.start(); // 休眠2秒钟,确保计时器顺利执行! Thread.sleep(2000); alarm.stop(); assertEquals(1, alarm.trigerTimes); context.assertIsSatisfied(); }
Example 4
Source File: AlarmServiceTest.java From androidtestdebug with MIT License | 6 votes |
public void testAlarmService() throws InterruptedException { Intent startIntent = new Intent(getContext(),AlarmService.class); startIntent.putExtra("TIME", new Date(2111, 12, 15, 16, 15, 0).getTime()); startService(startIntent); AlarmService service = (AlarmService)getService(); Mockery context = new Mockery(); final IGetDate gd = context.mock(IGetDate.class); context.checking(new Expectations() {{ atLeast(1).of(gd).Now(); will(returnValue( new Date(2111, 12, 15, 16, 15, 0))); }}); service.getAlarm().setIGetDate(gd); Thread.sleep(2000); assertEquals(1, service.getAlarm().trigerTimes); context.assertIsSatisfied(); }
Example 5
Source File: AlarmServiceTest.java From androidtestdebug with MIT License | 6 votes |
public void testAlarm2() throws InterruptedException { Option option = new Option(); option.alarmTime = new Date(1, 12, 15, 16, 15, 0); option.repeatSetting = RepeatSetting.EveryDay; Mockery context = new Mockery(); final IGetDate gd = context.mock(IGetDate.class); context.checking(new Expectations() {{ atLeast(1).of(gd).Now(); will(returnValue(new Date(1, 12, 15, 16, 15, 0))); }}); TestableAlarm alarm = new TestableAlarm(option, gd, this.getContext()); alarm.start(); // 休眠2秒钟,确保计时器顺利执行! Thread.sleep(2000); alarm.stop(); assertEquals(1, alarm.trigerTimes); context.assertIsSatisfied(); }
Example 6
Source File: DpsDepositFacadeImplTest.java From webcurator with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void test_submission_of_wct_sip() throws Exception { FileInputStream fis = new FileInputStream(wctMetsPath); int fileSize = fis.available(); byte[] binaryData = new byte[fileSize]; fis.read(binaryData); String wctSip = new String(binaryData); Mockery mockContext = constructMockContext(); final DepositWebServicesFactory depositWebServicesFactory = mockContext.mock(DepositWebServicesFactory.class); final DepositWebServices depositWebServices = mockContext.mock(DepositWebServices.class); final PdsClientFactory pdsClientFactory = mockContext.mock(PdsClientFactory.class); final PdsClient pdsClient = mockContext.mock(PdsClient.class); final DnxMapper dnxMapper = new DnxMapperImpl(new MetsWriterFactoryImpl()); final FileMover fileMover = mockContext.mock(FileMover.class); final PreDepositProcessor preDepositProcessor = new ArcIndexProcessor(); final DpsDepositFacade dpsDeposit = new DpsDepositFacadeImpl(depositWebServicesFactory, pdsClientFactory, fileMover, dnxMapper, preDepositProcessor); final String pdsSessionId = "pdsSessionId"; populateArcFileContents(); List<File> fileList = extractFileDetailsFrom(); final Map<String, String> parameters = populateDepositParameter(wctSip); mockContext.checking(new Expectations() { { one(depositWebServicesFactory).createInstance(with(any(WctDepositParameter.class))); will(returnValue(depositWebServices)); one(depositWebServices).submitDepositActivity(with(any(String.class)), with(any(String.class)), with(any(String.class)), with(any(String.class)), with(any(String.class))); will(returnValue(DepositResultConverterTest.buildMessage(false))); one(fileMover).move(with(any(MetsDocument.class)), with(any(List.class)), with(any(WctDepositParameter.class))); allowing(pdsClientFactory).createInstance(); will(returnValue(pdsClient)); allowing(pdsClient).init(with(any(String.class)), with(any(boolean.class))); allowing(pdsClient).login(with(any(String.class)), with(any(String.class)), with(any(String.class))); will(returnValue(pdsSessionId)); } }); DepositResult depositResult = dpsDeposit.deposit(parameters, fileList); if (depositResult.isError()) throw new RuntimeException("Submission to DPS failed, message from DPS: " + depositResult.getMessageDesciption()); mockContext.assertIsSatisfied(); assertThat(depositResult.getSipId(), is(notNullValue())); }
Example 7
Source File: FtpFileMoverTest.java From webcurator with Apache License 2.0 | 5 votes |
@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(); }
Example 8
Source File: FtpFileMoverTest.java From webcurator with Apache License 2.0 | 5 votes |
@Test public void test_calling_create_And_Change_To_Directory() throws IOException { Mockery mockContext = constructMockContext(); final FTPClient mockedFtpClient = mockContext.mock(FTPClient.class); final FtpClientFactory mockedFactory = mockContext.mock(FtpClientFactory.class); final String directoryName = "directoryName"; 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); one(mockedFtpClient).makeDirectory(directoryName); will(returnValue(true)); one(mockedFtpClient).changeWorkingDirectory(directoryName); } }); WctDepositParameter depositParameter = new WctDepositParameter(); FtpFileMover ftpFileMover = new FtpFileMover(mockedFactory); ftpFileMover.connect(depositParameter); ftpFileMover.createAndChangeToDirectory(directoryName); mockContext.assertIsSatisfied(); }
Example 9
Source File: FtpFileMoverTest.java From webcurator with Apache License 2.0 | 5 votes |
@Test public void test_store_file() throws IOException { Mockery mockContext = constructMockContext(); final FTPClient mockedFtpClient = mockContext.mock(FTPClient.class); final FtpClientFactory mockedFactory = mockContext.mock(FtpClientFactory.class); final String fileName = "directoryName"; final InputStream stream = new ByteArrayInputStream(fileName.getBytes()); final WctDepositParameter depositParameter = new WctDepositParameter(); 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); one(mockedFtpClient).storeFile(fileName, stream); will(returnValue(true)); } }); FtpFileMover ftpFileMover = new FtpFileMover(mockedFactory); ftpFileMover.connect(depositParameter); ftpFileMover.storeFile(fileName, stream); mockContext.assertIsSatisfied(); }
Example 10
Source File: FtpFileMoverTest.java From webcurator with Apache License 2.0 | 5 votes |
@Test public void test_close_disconnects_from_server() throws IOException { Mockery mockContext = constructMockContext(); final FTPClient mockedFtpClient = mockContext.mock(FTPClient.class); final FtpClientFactory mockedFactory = mockContext.mock(FtpClientFactory.class); final WctDepositParameter depositParameter = new WctDepositParameter(); 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); one(mockedFtpClient).disconnect(); } }); FtpFileMover ftpFileMover = new FtpFileMover(mockedFactory); ftpFileMover.connect(depositParameter); ftpFileMover.close(); mockContext.assertIsSatisfied(); }
Example 11
Source File: ArcIndexProcessorTest.java From webcurator with Apache License 2.0 | 4 votes |
@Test public void test_cdx_index_created_for_arc_file() throws IOException { Mockery mockContext = new Mockery(); final WctDataExtractor dataExtractor = mockContext.mock(WctDataExtractor.class); final List<ArchiveFile> arcFiles = new ArrayList<ArchiveFile>(); ArchiveFile archive1File = new FileSystemArchiveFile("application/octet-stream", "", TEST_ARC_1, DIRECTORY); arcFiles.add(archive1File); ArchiveFile archive2File = new FileSystemArchiveFile("application/octet-stream", "", TEST_ARC_2, DIRECTORY); arcFiles.add(archive2File); mockContext.checking(new Expectations() { { allowing(dataExtractor).getArchiveFiles(); will(returnValue(arcFiles)); one(dataExtractor).setArcIndexFile(with(any(ArchiveFile.class))); } }); ArcIndexProcessor processor = new ArcIndexProcessor(); File cdxFile = processor.process(tempDirectory, dataExtractor); BufferedReader br = new BufferedReader(new FileReader(cdxFile)); String line = null; int lineCount = 0; br.readLine(); // skip first line while ((line = br.readLine()) != null) { lineCount++; if (lineCount < 12) assertThat(line, containsString("TestArc1")); else assertThat(line, containsString("TestArc2")); } assertThat(lineCount, is(equalTo(22))); mockContext.assertIsSatisfied(); }