gudii9
asked on
junit example issue
package eePackage;
interface Appender
{
/**
* Appends an integer value to the end of the string.
* @param value the integer value to be appended.
* @return the string with the appended value.
*/
String append(final Integer value);
}
package eePackage;
interface Calculator
{
/**
* Multiplies two integer values and returns the result.
* @param a the first value.
* @param b the second value.
* @return the product of the multiplication.
*/
Integer multiply(final int a, final int b);
}
package eePackage;
public interface Reverser
{
/**
* Reverses a string.
* @param toBeReversed the string to be reversed.
* @return the reversed string.
*/
String reverse(String toBeReversed);
}
package eePackage;
public class Computer
{
private Calculator calculator;
private Appender appender;
private Reverser reverser;
/**
* Constructor.
*
* @param calculator the calculator class.
* @param appender the appender class.
* @param reverser the reverser class.
*/
public Computer(final Calculator calculator, final Appender appender, final Reverser reverser)
{
this.calculator = calculator;
this.appender = appender;
this.reverser = reverser;
}
public String compute(final int a, final int b)
{
Integer product = calculator.multiply(a, b);
return "";
}
}
package eePackage;
import org.jmock.Expectations;
import org.jmock.Mockery;
import junit.framework.TestCase;
public class ComputerTest extends TestCase
{
private Mockery mockery;
private Calculator calculator;
private Appender appender;
private Reverser reverser;
private Computer computer;
/**
* {@inheritDoc}
*/
@Override
public void setUp()
{
mockery = new Mockery();
calculator = mockery.mock(Calculator.class);
appender = mockery.mock(Appender.class);
reverser = mockery.mock(Reverser.class);
computer = new Computer(calculator, appender, reverser);
}
/**
* Tests the compute method.
*/
public void testCompute()
{
final Integer product = Integer.valueOf(200);
final int a = 10, b = 20;
final String someString = "a string ";
mockery.checking(new Expectations(){
{
one(calculator).multiply(a, b);
will(returnValue(product));
one(appender).append(product);
String appendedString = someString + product.toString();
will(returnValue(appendedString));
one(reverser).reverse(appendedString);
}
});
computer.compute(a, b);
mockery.assertIsSatisfied();
}
}
I am trying above example on RAD IDE from link
http://thejavablog.wordpress.com/2008/05/27/testing-with-jmock/
I saw option to import junit3 automatically which i did.
I see below import not coming automatically and creating issues
import org.jmock.Mockery;
private Mockery mockery;
Please advise on how to fix it
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Might be interesting for you:
ASKER
I thought IDEs like eclipse and RAD have default support for junit without necessity of adding copying the junit jars to project lib folder then going to build path and setting the build path with those libraries?
Compilation errors i saw earlier infront of below lines(i see red mark before them )
import org.jmock.Mockery;
private Mockery mockery;
Now those errors are not there which might have been gone as I set the classpath.
JunitJARS.jpg
Compilation errors i saw earlier infront of below lines(i see red mark before them )
import org.jmock.Mockery;
private Mockery mockery;
Now those errors are not there which might have been gone as I set the classpath.
JunitJARS.jpg
ASKER
please advise
ASKER
Does RAD/eclipse do this automatically for us?
When it does automaticallly when we need to do this step manually.
Please advise