Search in sources :

Example 71 with Mockery

use of org.jmock.Mockery in project teamcity-powershell by JetBrains.

the class PowerShellInfoTest method testSaveLoad.

@Test(dataProvider = "editionProvider")
public void testSaveLoad(@NotNull final PowerShellEdition edition) throws IOException {
    PowerShellInfo info = new PowerShellInfo(PowerShellBitness.x64, createTempDir(), "1.0", edition, "powershell.exe");
    final Mockery m = new Mockery();
    final BuildAgentConfiguration conf = m.mock(BuildAgentConfiguration.class);
    final Map<String, String> confParams = new HashMap<String, String>();
    m.checking(new Expectations() {

        {
            allowing(conf).getConfigurationParameters();
            will(returnValue(Collections.unmodifiableMap(confParams)));
            allowing(conf).addConfigurationParameter(with(any(String.class)), with(any(String.class)));
            will(new Action() {

                public Object invoke(final Invocation invocation) {
                    final String key = (String) invocation.getParameter(0);
                    final String value = (String) invocation.getParameter(1);
                    Assert.assertNotNull(key);
                    Assert.assertNotNull(value);
                    confParams.put(key, value);
                    return null;
                }

                public void describeTo(final Description description) {
                    description.appendText("add Parameters");
                }
            });
        }
    });
    final String propertyName = "powershell_" + info.getEdition().getValue() + "_" + info.getVersion() + "_" + info.getBitness().getValue();
    assertNull(conf.getConfigurationParameters().get(propertyName));
    assertNull(conf.getConfigurationParameters().get(propertyName + "_Path"));
    info.saveInfo(conf);
    assertEquals(info.getVersion(), conf.getConfigurationParameters().get(propertyName));
    assertEquals(info.getHome().getAbsolutePath(), conf.getConfigurationParameters().get(propertyName + "_Path"));
}
Also used : Expectations(org.jmock.Expectations) Action(org.jmock.api.Action) Description(org.hamcrest.Description) Invocation(org.jmock.api.Invocation) HashMap(java.util.HashMap) Mockery(org.jmock.Mockery) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) Test(org.testng.annotations.Test)

Example 72 with Mockery

use of org.jmock.Mockery in project activemq-artemis by apache.

the class ConfigTest method testJdbcLockConfigDefault.

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();
}
Also used : Expectations(org.jmock.Expectations) JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DatabaseMetaData(java.sql.DatabaseMetaData) Mockery(org.jmock.Mockery) DataSource(javax.sql.DataSource)

Example 73 with Mockery

use of org.jmock.Mockery in project i2p.i2p-bote by i2p.

the class TestUtil method createConfiguration.

/**
 * Creates a mock {@link Configuration} whose getKeyDerivationParametersFile() and
 * getPasswordFile() methods must be called at least once each.<br/>
 * Creates a file named derivparams in <code>testDir</code>.<br/>
 * The <code>getPasswordCacheDuration</code> method returns 1 (one minute).
 * @param testDir
 */
public static Configuration createConfiguration(File testDir) {
    final Synchroniser synchroniser = new Synchroniser();
    Mockery mockery = new Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
            // otherwise we get errors on threads
            setThreadingPolicy(synchroniser);
        }
    };
    final Configuration configuration = mockery.mock(Configuration.class);
    final File derivParametersFile = new File(testDir, "derivparams");
    mockery.checking(new Expectations() {

        {
            atLeast(1).of(configuration).getKeyDerivationParametersFile();
            will(returnValue(derivParametersFile));
        }
    });
    final File passwordFile = new File(testDir, "password");
    mockery.checking(new Expectations() {

        {
            atLeast(1).of(configuration).getPasswordFile();
            will(returnValue(passwordFile));
        }
    });
    mockery.checking(new Expectations() {

        {
            allowing(configuration).getPasswordCacheDuration();
            will(returnValue(1));
        }
    });
    return configuration;
}
Also used : Expectations(org.jmock.Expectations) Synchroniser(org.jmock.lib.concurrent.Synchroniser) Mockery(org.jmock.Mockery) File(java.io.File)

Example 74 with Mockery

use of org.jmock.Mockery in project pentaho-platform by pentaho.

the class BlockingQuartzJobTest method setUp.

@Before
public void setUp() throws Exception {
    mockery = new Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    underlyingJob = mockery.mock(Job.class);
    context = mockery.mock(JobExecutionContext.class);
    blockoutManager = mockery.mock(IBlockoutManager.class);
    logger = mockery.mock(Log.class);
}
Also used : Log(org.apache.commons.logging.Log) JobExecutionContext(org.quartz.JobExecutionContext) Job(org.quartz.Job) Mockery(org.jmock.Mockery) IBlockoutManager(org.pentaho.platform.api.scheduler2.IBlockoutManager) Before(org.junit.Before)

Example 75 with Mockery

use of org.jmock.Mockery in project gocd by gocd.

the class JobInstanceLogTest method setUp.

@Before
public void setUp() {
    context = new Mockery();
    context.setImposteriser(ClassImposteriser.INSTANCE);
    jobInstanceLog = new JobInstanceLog(null, new HashMap());
    defaultLogFile = new LogFile(new File("log20051209122103.xml"));
    rootFolder = new File("root");
    rootFolder.mkdirs();
    env = new SystemEnvironment();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HashMap(java.util.HashMap) Mockery(org.jmock.Mockery) File(java.io.File) JobInstanceLog(com.thoughtworks.go.domain.JobInstanceLog) Before(org.junit.Before)

Aggregations

Mockery (org.jmock.Mockery)148 Expectations (org.jmock.Expectations)118 Test (org.junit.Test)77 Before (org.junit.Before)28 ArrayList (java.util.ArrayList)24 Date (java.util.Date)21 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)17 File (java.io.File)15 BeforeMethod (org.testng.annotations.BeforeMethod)15 Synchroniser (org.jmock.lib.concurrent.Synchroniser)14 List (java.util.List)11 ActorDTO (com.management.dto.ActorDTO)7 FanZoneDTO (com.management.dto.FanZoneDTO)6 PropsDTO (com.management.dto.PropsDTO)6 ActorPerformancesRepository (com.management.repositories.ActorPerformancesRepository)6 ActorRepository (com.management.repositories.ActorRepository)6 CinemaTheatreRepository (com.management.repositories.CinemaTheatreRepository)6 EventRepository (com.management.repositories.EventRepository)6 FriendsListRepository (com.management.repositories.FriendsListRepository)6 PerformanceRepository (com.management.repositories.PerformanceRepository)6