org.jmock.Mockery Java Examples

The following examples show how to use org.jmock.Mockery. 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: RenderLayerTest.java    From mini2Dx with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: DeploymentBuildAgentPodTemplateProviderTest.java    From teamcity-kubernetes-plugin with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
@Override
protected void setUp() throws Exception {
    super.setUp();
    m = new Mockery();
    ServerSettings serverSettings = m.mock(ServerSettings.class);
    KubeAuthStrategyProvider authStrategies = m.mock(KubeAuthStrategyProvider.class);
    myDeploymentContentProvider = m.mock(DeploymentContentProvider.class);
    final ExecutorServices executorServices = m.mock(ExecutorServices.class);
    m.checking(new Expectations(){{
        allowing(serverSettings).getServerUUID(); will(returnValue("server uuid"));
        allowing(authStrategies).get(with(UnauthorizedAccessStrategy.ID)); will(returnValue(myAuthStrategy));
        ScheduledExecutorService ses = new ScheduledThreadPoolExecutor(1);
        allowing(executorServices).getNormalExecutorService(); will(returnValue(ses));
    }});
    TempFiles tempFiles = new TempFiles();
    final ServerPaths serverPaths = new ServerPaths(tempFiles.createTempDir());
    final EventDispatcher<BuildServerListener> eventDispatcher = EventDispatcher.create(BuildServerListener.class);
    myNameGenerator = new KubePodNameGeneratorImpl(serverPaths, executorServices, eventDispatcher);
    myPodTemplateProvider = new DeploymentBuildAgentPodTemplateProvider(serverSettings, myDeploymentContentProvider);
}
 
Example #3
Source File: ArtifactPathHelperTest.java    From teamcity-symbol-server with Apache License 2.0 6 votes vote down vote up
@Test(dataProvider = "testPaths")
public void testPathTransformation(String prefix, String fileName, String expectedPath) {
  Mockery m = new Mockery();
  ExtensionHolder extensionHolder = m.mock(ExtensionHolder.class);
  BuildProgressLogger logger = m.mock(BuildProgressLogger.class);
  InternalPropertiesHolder propertiesHolder = m.mock(InternalPropertiesHolder.class);
  ArtifactPathHelper helper = new ArtifactPathHelper(extensionHolder);
  ZipPreprocessor zipPreprocessor = new ZipPreprocessor(logger, new File("."), propertiesHolder);

  m.checking(new Expectations(){{
    allowing(extensionHolder).getExtensions(with(ArchivePreprocessor.class));
    will(returnValue(Collections.singletonList(zipPreprocessor)));
  }});

  Assert.assertEquals(helper.concatenateArtifactPath(prefix, fileName), expectedPath);
}
 
Example #4
Source File: RenderNodeTest.java    From mini2Dx with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
	Mdx.platform = Platform.WINDOWS;

	parentElement.setVisibility(Visibility.VISIBLE);
	parentElement.setPreferredContentWidth(PARENT_WIDTH);
	parentElement.setPreferredContentHeight(PARENT_HEIGHT);
	
	uiElement.setVisibility(Visibility.VISIBLE);
	uiElement.setPreferredContentWidth(ELEMENT_WIDTH);
	uiElement.setPreferredContentHeight(ELEMENT_HEIGHT);
	parentRenderNode.addChild(renderNode);
	
	mockery = new Mockery();
	mockery.setImposteriser(ClassImposteriser.INSTANCE);
	
	layoutState = mockery.mock(LayoutState.class);
	renderTree = mockery.mock(UiContainerRenderTree.class);
}
 
Example #5
Source File: FlexDirectionTest.java    From mini2Dx with Apache License 2.0 6 votes vote down vote up
@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 #6
Source File: ChannelInitializerTest.java    From nanofix with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: FtpFileMoverTest.java    From webcurator with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: FileMoverTest.java    From webcurator with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: AlarmMockTest.java    From androidtestdebug with MIT License 6 votes vote down vote up
@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 #10
Source File: AlarmServiceTest.java    From androidtestdebug with MIT License 6 votes vote down vote up
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 #11
Source File: AlarmServiceTest.java    From androidtestdebug with MIT License 6 votes vote down vote up
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 #12
Source File: StatisticsMonitorJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public void setUp() throws Exception {
  super.setUp();
  this.mockContext = new Mockery() {{
    setImposteriser(ClassImposteriser.INSTANCE);
  }};
  
  this.log = new PureLogWriter(LogWriterImpl.levelNameToCode("config"));
  
  final long startTime = System.currentTimeMillis();
  this.manager = new TestStatisticsManager(
      1, 
      "StatisticsMonitorJUnitTest", 
      startTime, 
      log);
  
  final StatArchiveHandlerConfig mockStatArchiveHandlerConfig = this.mockContext.mock(StatArchiveHandlerConfig.class, "StatisticsMonitorJUnitTest$StatArchiveHandlerConfig");
  this.mockContext.checking(new Expectations() {{
    allowing(mockStatArchiveHandlerConfig).getArchiveFileName();
    will(returnValue(new File("")));
    allowing(mockStatArchiveHandlerConfig).getArchiveFileSizeLimit();
    will(returnValue(0));
    allowing(mockStatArchiveHandlerConfig).getArchiveDiskSpaceLimit();
    will(returnValue(0));
    allowing(mockStatArchiveHandlerConfig).getSystemId();
    will(returnValue(1));
    allowing(mockStatArchiveHandlerConfig).getSystemStartTime();
    will(returnValue(startTime));
    allowing(mockStatArchiveHandlerConfig).getSystemDirectoryPath();
    will(returnValue(""));
    allowing(mockStatArchiveHandlerConfig).getProductDescription();
    will(returnValue("StatisticsMonitorJUnitTest"));
  }});

  StatisticsSampler sampler = new TestStatisticsSampler(manager);
  this.sampleCollector = new SampleCollector(sampler);
  this.sampleCollector.initialize(mockStatArchiveHandlerConfig, NanoTimer.getTime());
}
 
Example #13
Source File: RenderPipelineTest.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	mockery = new Mockery();
	mockery.setImposteriser(ClassImposteriser.INSTANCE);
	
	operation1 = mockery.mock(RenderOperation.class, "operation1");
	operation2 = mockery.mock(RenderOperation.class, "operation2");
	gc = mockery.mock(GameContainer.class);
	g = mockery.mock(Graphics.class);
	
	pipeline = new RenderPipeline();
	pipeline.add(operation1);
	pipeline.add(operation2);
}
 
Example #14
Source File: SSHExecProcessAdapterTest.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setup() {
  myContext = new Mockery();
  myContext.setImposteriser(ClassImposteriser.INSTANCE);

  mySessionProvider = myContext.mock(SSHSessionProvider.class);
  mySession = myContext.mock(Session.class);
  myChannel = myContext.mock(ChannelExec.class);
  myLogger = myContext.mock(BuildProgressLogger.class);
  myAdapter = newAdapter(myLogger);
  commonExpectations();
}
 
Example #15
Source File: DeployerRunTypeTest.java    From teamcity-deployer-plugin with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void setUp() {
  myContext = new Mockery();
  final RunTypeRegistry registry = myContext.mock(RunTypeRegistry.class);
  final PluginDescriptor descriptor = myContext.mock(PluginDescriptor.class);
  myContext.checking(new Expectations() {{
    allowing(registry).registerRunType(with(aNonNull(SSHExecRunType.class)));
  }});
  createRunType(registry, descriptor);
}
 
Example #16
Source File: SampleCollectorJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
  super.setUp();
  new File(dir).mkdir();
  this.mockContext = new Mockery() {{
    setImposteriser(ClassImposteriser.INSTANCE);
  }};
  LogWriterI18n log = new PureLogWriter(LogWriterImpl.levelNameToCode("config"));
  final long startTime = System.currentTimeMillis();
  this.manager = new TestStatisticsManager(
      1, 
      "SampleCollectorJUnitTest", 
      startTime, 
      log);
  
  final StatArchiveHandlerConfig mockStatArchiveHandlerConfig = this.mockContext.mock(StatArchiveHandlerConfig.class, "SampleCollectorJUnitTest$StatArchiveHandlerConfig");
  this.mockContext.checking(new Expectations() {{
    allowing(mockStatArchiveHandlerConfig).getArchiveFileName();
    will(returnValue(new File("")));
    allowing(mockStatArchiveHandlerConfig).getArchiveFileSizeLimit();
    will(returnValue(0));
    allowing(mockStatArchiveHandlerConfig).getArchiveDiskSpaceLimit();
    will(returnValue(0));
    allowing(mockStatArchiveHandlerConfig).getSystemId();
    will(returnValue(1));
    allowing(mockStatArchiveHandlerConfig).getSystemStartTime();
    will(returnValue(startTime));
    allowing(mockStatArchiveHandlerConfig).getSystemDirectoryPath();
    will(returnValue(""));
    allowing(mockStatArchiveHandlerConfig).getProductDescription();
    will(returnValue("SampleCollectorJUnitTest"));
  }});

  StatisticsSampler sampler = new TestStatisticsSampler(manager);
  this.sampleCollector = new SampleCollector(sampler);
  this.sampleCollector.initialize(mockStatArchiveHandlerConfig, NanoTimer.getTime());
}
 
Example #17
Source File: FileMoverTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
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 #18
Source File: TcpTransportTest.java    From nanofix with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    mockery = new Mockery();
    mockery.setImposteriser(ClassImposteriser.INSTANCE);
    publishingTransportObserver = mockery.mock(PublishingConnectionObserver.class);
    serverSocketChannel = mockery.mock(DelegatingServerSocketChannel.class);
    socketFactory = mockery.mock(SocketFactory.class);
    socketAddress = new InetSocketAddress("host", 222);
}
 
Example #19
Source File: FtpFileMoverTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
private Mockery constructMockContext() {
    Mockery mockContext = new Mockery() {
        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    return mockContext;
}
 
Example #20
Source File: FtpFileMoverTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: FtpFileMoverTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@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 #22
Source File: ConfigTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@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 #23
Source File: RegionPathConverterJUnitTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  mockContext = new Mockery() {
    {
      setImposteriser(ClassImposteriser.INSTANCE);
    }
  };
}
 
Example #24
Source File: FtpFileMoverTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@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 #25
Source File: FtpFileMoverTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
@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 #26
Source File: DivRenderNodeTest.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@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 #27
Source File: DpsDepositFacadeImplTest.java    From webcurator with Apache License 2.0 5 votes vote down vote up
private Mockery constructMockContext() {
    Mockery mockContext = new Mockery() {
        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    return mockContext;
}
 
Example #28
Source File: RenderingEntitySystemTest.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    renderedIds = new HashSet<Integer>();
    system = new RenderingEntitySystemTest();

    mockery = new Mockery();
    graphics = mockery.mock(Graphics.class);

    WorldConfiguration configuration = new WorldConfiguration();
    configuration.setSystem(system);
    world = new MdxWorld(configuration);
}
 
Example #29
Source File: ConfigTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
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 #30
Source File: WrappingKeySerializingExecutorTest.java    From c5-replicator with Apache License 2.0 5 votes vote down vote up
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"));
  }});
}