use of org.jmock.Mockery in project gocd by gocd.
the class JobStatusCacheTest method shouldLoadMostRecentInstanceFromDBOnlyOnce.
@Test
public void shouldLoadMostRecentInstanceFromDBOnlyOnce() throws SQLException {
Mockery mockery = new Mockery();
final StageDao mock = mockery.mock(StageDao.class);
final JobInstance instance = JobInstanceMother.passed("linux-firefox");
final List<JobInstance> found = new ArrayList<>();
found.add(instance);
mockery.checking(new Expectations() {
{
one(mock).mostRecentJobsForStage("pipeline", "stage");
will(returnValue(found));
}
});
JobConfigIdentifier identifier = new JobConfigIdentifier(instance.getPipelineName(), instance.getStageName(), instance.getName());
JobStatusCache cache = new JobStatusCache(mock);
assertThat(cache.currentJob(identifier).getState(), is(instance.getState()));
// call currentJob for the second time, should not call jobInstanceDao now
assertThat(cache.currentJob(identifier).getState(), is(instance.getState()));
}
use of org.jmock.Mockery in project gocd by gocd.
the class StageStatusCacheTest method shouldLoadMostRecentInstanceFromDBOnlyOnce.
@Test
public void shouldLoadMostRecentInstanceFromDBOnlyOnce() throws SQLException {
Mockery mockery = new Mockery();
final StageDao mock = mockery.mock(StageDao.class);
final StageConfigIdentifier identifier = new StageConfigIdentifier("cruise", "dev");
final Stage instance = StageMother.failingStage("dev");
mockery.checking(new Expectations() {
{
one(mock).mostRecentStage(identifier);
will(returnValue(instance));
}
});
StageStatusCache cache = new StageStatusCache(mock);
assertThat(cache.currentStage(identifier).getName(), is(instance.getName()));
// call currentStage for the second time, should not call stageDao now
assertThat(cache.currentStage(identifier).getName(), is(instance.getName()));
}
use of org.jmock.Mockery in project gocd by gocd.
the class StageResultTypeHandlerCallbackTest method assertMaps.
private void assertMaps(final String str, StageResult value) throws SQLException {
final ResultGetter resultGetter;
Mockery context = new Mockery() {
{
setImposteriser(ClassImposteriser.INSTANCE);
}
};
resultGetter = context.mock(ResultGetter.class);
context.checking(new Expectations() {
{
one(resultGetter).getString();
will(returnValue(str));
}
});
StageResult result = (StageResult) callback.getResult(resultGetter);
assertThat(result, is(equal(value)));
final ParameterSetter parameterSetter = context.mock(ParameterSetter.class);
context.checking(new Expectations() {
{
one(parameterSetter).setString(str);
}
});
callback.setParameter(parameterSetter, value);
}
use of org.jmock.Mockery in project gocd by gocd.
the class StageStateTypeHandlerCallbackTest method assertMaps.
private void assertMaps(final String str, StageState value) throws SQLException {
final ResultGetter resultGetter;
Mockery context = new Mockery() {
{
setImposteriser(ClassImposteriser.INSTANCE);
}
};
resultGetter = context.mock(ResultGetter.class);
context.checking(new Expectations() {
{
one(resultGetter).getString();
will(returnValue(str));
}
});
StageState result = (StageState) callback.getResult(resultGetter);
assertThat(result, is(equal(value)));
final ParameterSetter parameterSetter = context.mock(ParameterSetter.class);
context.checking(new Expectations() {
{
one(parameterSetter).setString(str);
}
});
callback.setParameter(parameterSetter, value);
}
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();
}
Aggregations