IE. Your default JRE might be the MyEclipse 6.0.
You install and add Java 1.5 JRE and make this your default.
Then three months later you create a new workspace.
Low and behold this new workspace does not know about the 1.5 JRE.
package uk.co.utilisoft.entrecaweb.web.validators;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.easymock.MockControl;
public class TryOldEasyMock extends TestCase{
public void testSingleCall(){
List<String> list = new ArrayList<String>();
list.add("hello");
MockControl control = MockControl.createControl(TestMock1.class);
TestMock1 mock = (TestMock1)control.getMock();
ClassUnderTest1 classUnderTest = new ClassUnderTest1();
classUnderTest.setService(mock);
control.expectAndDefaultReturn(mock.getLength("hello"), 5);
control.replay();
assertEquals(5, classUnderTest.getLength(list));
control.verify();
}
public void testTwoCalls(){
List<String> list = new ArrayList<String>();
list.add("hello");
list.add("bye");
MockControl control = MockControl.createControl(TestMock1.class);
TestMock1 mock = (TestMock1)control.getMock();
ClassUnderTest1 classUnderTest = new ClassUnderTest1();
classUnderTest.setService(mock);
control.expectAndDefaultReturn(mock.getLength("hello"), 5);
control.expectAndDefaultReturn(mock.getLength("bye"), 95);
control.replay();
assertEquals("this is the wrong value & should fail.", 190, classUnderTest.getLength(list));
assertEquals("this is the correct value & should pass.", 100, classUnderTest.getLength(list));
control.verify();
}
}
class ClassUnderTest1{
private TestMock1 service;
public void setService(TestMock1 service) {
this.service = service;
}
public int getLength(List<String> someText)
{
int total = 0;
for (String value : someText) {
total += service.getLength(value);
}
return total;
}
}
interface TestMock1
{
public int getLength(String someText);
}
package uk.co.utilisoft.entrecaweb.web.validators;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import static org.easymock.classextension.EasyMock.*;
public class TryEasyMockTest extends TestCase {
public void testSingleCall()
{
List<String> list = new ArrayList<String>();
list.add("hello");
TestMock mock = createMock(TestMock.class);
expect(mock.getLength("hello")).andReturn(5);
ClassUnderTest classUnderTest = new ClassUnderTest();
classUnderTest.setService(mock);
replay(mock);
assertEquals(5, classUnderTest.getLength(list));
verify(mock);
}
public void testTwoCalls()
{
List<String> list = new ArrayList<String>();
list.add("hello");
list.add("bye");
TestMock mock = createMock(TestMock.class);
expect(mock.getLength("hello")).andReturn(5);
expect(mock.getLength("bye")).andReturn(95);
ClassUnderTest classUnderTest = new ClassUnderTest();
classUnderTest.setService(mock);
replay(mock);
assertEquals(100, classUnderTest.getLength(list));
verify(mock);
}
}
class ClassUnderTest{
private TestMock service;
public void setService(TestMock service) {
this.service = service;
}
public int getLength(List<String> someText)
{
int total = 0;
for (String value : someText) {
total += service.getLength(value);
}
return total;
}
}
class TestMock
{
public int getLength(String someText){
return someText.length();
}
}