Java Code Examples for org.jmock.Mockery#checking()
The following examples show how to use
org.jmock.Mockery#checking() .
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: 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 2
Source File: FlexDirectionTest.java From mini2Dx with Apache License 2.0 | 6 votes |
@Before public void setUp() { Mdx.locks = new JvmLocks(); mockery = new Mockery(); mockery.setImposteriser(ClassImposteriser.INSTANCE); layoutState = mockery.mock(LayoutState.class); renderTree = mockery.mock(UiContainerRenderTree.class); mockery.checking(new Expectations() { { atLeast(1).of(layoutState).getUiContainerRenderTree(); will(returnValue(renderTree)); atLeast(1).of(renderTree).transferLayoutDeferred(with(any(Array.class))); } }); }
Example 3
Source File: ChannelInitializerTest.java From nanofix with Apache License 2.0 | 6 votes |
@Before public void setUp() throws Exception { mockery = new Mockery(); mockery.setImposteriser(ClassImposteriser.INSTANCE); transport = mockery.mock(Transport.class); byteChannelReader = mockery.mock(ByteChannelReader.class); outboundMessageHandler = mockery.mock(OutboundMessageHandler.class); writableByteChannel = mockery.mock(WritableByteChannel.class); readableByteChannel = mockery.mock(ReadableByteChannel.class); mockery.checking(new Expectations() { { ignoring(writableByteChannel); } }); }
Example 4
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 5
Source File: RenderLayerTest.java From mini2Dx with Apache License 2.0 | 6 votes |
@Before public void setUp() { parentElement.setVisibility(Visibility.VISIBLE); uiElement1.setVisibility(Visibility.VISIBLE); uiElement2.setVisibility(Visibility.VISIBLE); mockery = new Mockery(); mockery.setImposteriser(ClassImposteriser.INSTANCE); layoutState = mockery.mock(LayoutState.class); renderTree = mockery.mock(UiContainerRenderTree.class); renderLayer.add(renderNode1); renderLayer.add(renderNode2); mockery.checking(new Expectations() { { atLeast(1).of(renderTree).transferLayoutDeferred(with(any(Array.class))); } }); }
Example 6
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 7
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 8
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 9
Source File: WrappingKeySerializingExecutorTest.java From c5-replicator with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static void allowSubmitAndThen(Mockery context, ExecutorService executorService, org.jmock.internal.State state) { context.checking(new Expectations() {{ allowing(executorService).submit(with.<Callable>is(any(Callable.class))); then(state); allowing(executorService).submit(with.is(any(Runnable.class)), with.is(any(Object.class))); then(state); allowing(executorService).submit(with.<Runnable>is(any(Runnable.class))); then(state); allowing(executorService).execute(with.is(any(Runnable.class))); then(state); }}); }
Example 10
Source File: WrappingKeySerializingExecutorTest.java From c5-replicator with Apache License 2.0 | 5 votes |
public static void allowSubmitOrExecuteOnce(Mockery context, ExecutorService executorService) { final States submitted = context.states("submitted").startsAs("no"); context.checking(new Expectations() {{ allowSubmitAndThen(context, executorService, submitted.is("yes")); doNowAllowSubmitOnce(context, executorService, submitted.is("yes")); }}); }
Example 11
Source File: FileMoverTest.java From webcurator with Apache License 2.0 | 5 votes |
private void createExpectations(Mockery mockContext, final FileMoverStrategy mockedFileMoverStrategy, final WctDepositParameter depositParameter) throws IOException { mockContext.checking(new Expectations() { { one(mockedFileMoverStrategy).connect(depositParameter); // 1. change to deposit, 2. change to content, 3. change to streams exactly(3).of(mockedFileMoverStrategy).createAndChangeToDirectory(with(any(String.class))); exactly(2).of(mockedFileMoverStrategy).storeFile(with(any(String.class)), with(any(InputStream.class))); one(mockedFileMoverStrategy).close(); } }); }
Example 12
Source File: DivRenderNodeTest.java From mini2Dx with Apache License 2.0 | 5 votes |
@Before public void setUp() { mockery = new Mockery(); mockery.setImposteriser(ClassImposteriser.INSTANCE); theme = mockery.mock(UiTheme.class); renderTree = mockery.mock(UiContainerRenderTree.class); div.setFlexLayout("flex-col:xs-3c"); div.setVisibility(Visibility.VISIBLE); flexRow1.setVisibility(Visibility.VISIBLE); flexRow2.setVisibility(Visibility.VISIBLE); rowRenderNode1.addChild(renderNode1); rowRenderNode1.addChild(renderNode2); rowRenderNode2.addChild(renderNode3); rowRenderNode2.addChild(renderNode4); divRenderNode.addChild(rowRenderNode1); divRenderNode.addChild(rowRenderNode2); mockery.checking(new Expectations() { { atLeast(1).of(renderTree).transferLayoutDeferred(with(any(Array.class))); } }); }
Example 13
Source File: ConfigTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
public void testJdbcLockConfigDefault() throws Exception { JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter(); Mockery context = new Mockery(); final DataSource dataSource = context.mock(DataSource.class); final Connection connection = context.mock(Connection.class); final DatabaseMetaData metadata = context.mock(DatabaseMetaData.class); final ResultSet result = context.mock(ResultSet.class); adapter.setDataSource(dataSource); adapter.setCreateTablesOnStartup(false); context.checking(new Expectations() {{ allowing(dataSource).getConnection(); will(returnValue(connection)); allowing(connection).getMetaData(); will(returnValue(metadata)); allowing(connection); allowing(metadata).getDriverName(); will(returnValue("Some_Unknown_driver")); allowing(result).next(); will(returnValue(true)); }}); adapter.start(); assertEquals("has the default locker", adapter.getLocker().getClass(), DefaultDatabaseLocker.class); adapter.stop(); }
Example 14
Source File: ConfigTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testJdbcLockConfigOverride() throws Exception { JDBCPersistenceAdapter adapter = new JDBCPersistenceAdapter(); Mockery context = new Mockery(); final DataSource dataSource = context.mock(DataSource.class); final Connection connection = context.mock(Connection.class); final DatabaseMetaData metadata = context.mock(DatabaseMetaData.class); final ResultSet result = context.mock(ResultSet.class); adapter.setDataSource(dataSource); adapter.setCreateTablesOnStartup(false); context.checking(new Expectations() {{ allowing(dataSource).getConnection(); will(returnValue(connection)); allowing(connection).getMetaData(); will(returnValue(metadata)); allowing(connection); allowing(metadata).getDriverName(); will(returnValue("Microsoft_SQL_Server_2005_jdbc_driver")); allowing(result).next(); will(returnValue(true)); }}); adapter.start(); assertTrue("has the locker override", adapter.getLocker() instanceof TransactDatabaseLocker); adapter.stop(); }
Example 15
Source File: CommandlineBuildProcessFactoryTest.java From TeamCity.Virtual with Apache License 2.0 | 5 votes |
@BeforeMethod @Override protected void setUp() throws Exception { super.setUp(); m = new Mockery(); myWorkDir = createTempDir(); myFacade = m.mock(BuildProcessFacade.class); myRootContext = m.mock(BuildRunnerContext.class, "root-context"); mySubContext = m.mock(BuildRunnerContext.class, "sub-context"); myBuild = m.mock(AgentRunningBuild.class); myProcess = m.mock(BuildProcess.class); myLogger = m.mock(BuildProgressLogger.class); myFactory = new CommandlineBuildProcessFactoryImpl(myFacade); m.checking(new Expectations(){{ oneOf(myFacade).createBuildRunnerContext(myBuild, SimpleRunnerConstants.TYPE, myWorkDir.getPath(), myRootContext); will(returnValue(mySubContext)); allowing(myRootContext).getBuild(); will(returnValue(myBuild)); allowing(mySubContext).getBuild(); will(returnValue(myBuild)); allowing(myBuild).getBuildLogger(); will(returnValue(myLogger)); allowing(myLogger).message(with(any(String.class))); oneOf(myFacade).createExecutable(myBuild, mySubContext); will(returnValue(myProcess)); }}); }
Example 16
Source File: SymbolsCacheTest.java From teamcity-symbol-server with Apache License 2.0 | 5 votes |
@Test public void testCacheEntryInvalidation() { SymbolsCache symbolsCache = new SymbolsCache(myFixture.getEventDispatcher()); Mockery m = new Mockery(); AtomicInteger integer = new AtomicInteger(); BuildMetadataEntry entry = m.mock(BuildMetadataEntry.class); String key = "key"; Function<String, BuildMetadataEntry> entryFunction = s -> { integer.incrementAndGet(); return entry; }; m.checking(new Expectations(){{ exactly(3).of(entry).getBuildId(); will(returnValue(123L)); }}); // Cache entry BuildMetadataEntry cacheEntry1 = symbolsCache.getEntry(key, entryFunction); Assert.assertNotNull(cacheEntry1); Assert.assertEquals(cacheEntry1, entry); // Remove it symbolsCache.removeEntry(key); // Cache entry again BuildMetadataEntry cacheEntry2 = symbolsCache.getEntry(key, entryFunction); Assert.assertNotNull(cacheEntry1); Assert.assertEquals(cacheEntry2, entry); Assert.assertEquals(integer.get(), 2); }
Example 17
Source File: WrappingKeySerializingExecutorTest.java From c5-replicator with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") private static void doNowAllowSubmitOnce(Mockery context, ExecutorService executorService, org.jmock.internal.State state) { context.checking(new Expectations() {{ never(executorService).submit(with.<Callable>is(any(Callable.class))); when(state); never(executorService).submit(with.is(any(Runnable.class)), with.is(any(Object.class))); when(state); never(executorService).submit(with.<Runnable>is(any(Runnable.class))); when(state); never(executorService).execute(with.is(any(Runnable.class))); when(state); }}); }
Example 18
Source File: CargoBuildProcessAdapterHttpsTest.java From teamcity-deployer-plugin with Apache License 2.0 | 4 votes |
@BeforeMethod @Override public void setUp() throws Exception { final File extractDir = createTempDir(); final File cfgDir = createTempDir(); final String fileName = "apache-tomcat-7.0.54.zip"; final File zipDistribution = getTestResource(fileName); final ZipURLInstaller installer = new ZipURLInstaller(zipDistribution.toURI().toURL()); installer.setExtractDir(extractDir.getAbsolutePath()); installer.install(); LocalConfiguration configuration = new Tomcat7xStandaloneLocalConfiguration(cfgDir.getAbsolutePath()); testPort = NetworkUtil.getFreePort(DEPLOYER_DEFAULT_PORT); configuration.setProperty(ServletPropertySet.PORT, String.valueOf(testPort)); configuration.setProperty(ServletPropertySet.USERS, "tomcat:tomcat:manager-script"); configuration.setProperty(TomcatPropertySet.AJP_PORT, String.valueOf(NetworkUtil.getFreePort(8009))); configuration.setProperty(TomcatPropertySet.CONNECTOR_KEY_STORE_FILE, getTestResource("ftpserver.jks").getAbsolutePath()); configuration.setProperty(TomcatPropertySet.CONNECTOR_KEY_STORE_PASSWORD, "password"); configuration.setProperty(TomcatPropertySet.CONNECTOR_KEY_ALIAS, "localhost"); configuration.setProperty(TomcatPropertySet.HTTP_SECURE, "true"); configuration.setProperty(GeneralPropertySet.PROTOCOL, "https"); myDefaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String s, SSLSession sslSession) { return true; // new versions of Java do not allow to connect to localhost by SSL, here we suppress this behavior } }); myTomcat = (InstalledLocalContainer) new DefaultContainerFactory().createContainer( "tomcat7x", ContainerType.INSTALLED, configuration); myTomcat.setHome(installer.getHome()); myTomcat.start(); Mockery mockeryCtx = new Mockery(); myContext = mockeryCtx.mock(BuildRunnerContext.class); final AgentRunningBuild build = mockeryCtx.mock(AgentRunningBuild.class); final BuildProgressLogger logger = new NullBuildProgressLogger(); workingDir = createTempDir(); mockeryCtx.checking(new Expectations() {{ allowing(myContext).getWorkingDirectory(); will(returnValue(workingDir)); allowing(myContext).getBuild(); will(returnValue(build)); allowing(myContext).getRunnerParameters(); will(returnValue(myRunnerParameters)); allowing(build).getBuildLogger(); will(returnValue(logger)); }}); myRunnerParameters.put(DeployerRunnerConstants.PARAM_CONTAINER_TYPE, "tomcat7x"); myRunnerParameters.put(CargoRunnerConstants.USE_HTTPS, "true"); }
Example 19
Source File: CargoBuildProcessAdapterTest.java From teamcity-deployer-plugin with Apache License 2.0 | 4 votes |
@BeforeMethod @Override public void setUp() throws Exception { super.setUp(); final File extractDir = createTempDir(); final File cfgDir = createTempDir(); final String fileName = "apache-tomcat-7.0.54.zip"; final File zipDistribution = getTestResource(fileName); final ZipURLInstaller installer = new ZipURLInstaller(zipDistribution.toURI().toURL()); installer.setExtractDir(extractDir.getAbsolutePath()); installer.install(); LocalConfiguration configuration = new Tomcat7xStandaloneLocalConfiguration(cfgDir.getAbsolutePath()); testPort = NetworkUtil.getFreePort(DEPLOYER_DEFAULT_PORT); configuration.setProperty(ServletPropertySet.PORT, String.valueOf(testPort)); configuration.setProperty(TomcatPropertySet.AJP_PORT, String.valueOf(NetworkUtil.getFreePort(8009))); configuration.setProperty(ServletPropertySet.USERS, "tomcat:tomcat:manager-script"); myTomcat = (InstalledLocalContainer) new DefaultContainerFactory().createContainer( "tomcat7x", ContainerType.INSTALLED, configuration); myTomcat.setHome(installer.getHome()); myTomcat.start(); Mockery mockeryCtx = new Mockery(); myContext = mockeryCtx.mock(BuildRunnerContext.class); final AgentRunningBuild build = mockeryCtx.mock(AgentRunningBuild.class); final BuildProgressLogger logger = new NullBuildProgressLogger(); workingDir = createTempDir(); mockeryCtx.checking(new Expectations() {{ allowing(myContext).getWorkingDirectory(); will(returnValue(workingDir)); allowing(myContext).getBuild(); will(returnValue(build)); allowing(myContext).getRunnerParameters(); will(returnValue(myRunnerParameters)); allowing(build).getBuildLogger(); will(returnValue(logger)); }}); myRunnerParameters.put(DeployerRunnerConstants.PARAM_CONTAINER_TYPE, "tomcat7x"); }
Example 20
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(); }