package org.jingle.mocquer.internal;
import org.jingle.mocquer.AssertionFailedError;
/**
* This class defines the mock object status
*
* @author JianLu
* @version 1.0 2004-10-26
* @since 1.0
*/
public class MockStatus {
/**
* Int value of PREPARE_PART_1_STATUS
*/
static final int PREPARE_PART_1_STATUS_INT = 0;
/**
* Int value of PREPARE_PART_2_STATUS
*/
static final int PREPARE_PART_2_STATUS_INT = 1;
/**
* Int value of WORKING_STATUS
*/
static final int WORKING_STATUS_INT = 2;
/**
* Int value of VERIFY_STATUS
*/
static final int VERIFY_STATUS_INT = 3;
/**
* Prepare status phase 1: Ready to call business method
* <p>In this status, mock object can setDefaultMatcher(), doBusinessMethod(), replay() and reset(). <p>
*/
public static MockStatus PREPARE_PART_1_STATUS = new MockStatus(PREPARE_PART_1_STATUS_INT) {
public MockStatus setDefaultMatcher() {
return this;
}
public MockStatus doBusinessMethod() {
return PREPARE_PART_2_STATUS;
}
public MockStatus replay() {
return WORKING_STATUS;
}
public MockStatus reset() {
return this;
}
};
/**
* Prepare status phase 2: Ready to define business method behavior
* <p>In this status, mock object can setMatcher(), setBehavior() and reset(). <p>
*/
public static MockStatus PREPARE_PART_2_STATUS = new MockStatus(PREPARE_PART_2_STATUS_INT) {
public MockStatus setMatcher() {
return this;
}
public MockStatus setBehavior() {
return PREPARE_PART_1_STATUS;
}
public MockStatus reset() {
return PREPARE_PART_1_STATUS;
}
};
/**
* Working status: Ready to be called
* <p>In this status, mock object can doBusinessMethod(), reset() and verify(). <p>
*/
public static MockStatus WORKING_STATUS = new MockStatus(WORKING_STATUS_INT) {
public MockStatus doBusinessMethod() {
return this;
}
public MockStatus reset() {
return PREPARE_PART_1_STATUS;
}
public MockStatus verify() {
return VERIFY_STATUS;
}
};
/**
* Verify status: Ready to be verified
* <p>In this status, mock object can reset() and replay(). <p>
*/
public static MockStatus VERIFY_STATUS = new MockStatus(VERIFY_STATUS_INT) {
public MockStatus reset() {
return PREPARE_PART_1_STATUS;
}
public MockStatus replay() {
return WORKING_STATUS;
}
};
int status;
/**
* Constructor
* @param status Status int value
*/
MockStatus(int status) {
this.status = status;
}
/**
* Call setDefaultMatcher() action on the status
* @return New status
*/
public MockStatus setDefaultMatcher() {
throw new AssertionFailedError("Invalid status");
}
/**
* Call setDefaultMatcher() action on the status
* @return New status
*/
public MockStatus setMatcher() {
throw new AssertionFailedError("Invalid status");
}
/**
* Call doBusinessMethod() action on the status
* @return New status
*/
public MockStatus doBusinessMethod() {
throw new AssertionFailedError("Invalid status");
}
/**
* Call setBehavior() action on the status
* @return New status
*/
public MockStatus setBehavior() {
throw new AssertionFailedError("Invalid status");
}
/**
* Call replay() action on the status
* @return New status
*/
public MockStatus replay() {
throw new AssertionFailedError("Invalid status");
}
/**
* Call reset() action on the status
* @return New status
*/
public MockStatus reset() {
throw new AssertionFailedError("Invalid status");
}
/**
* Call verify() action on the status
* @return New status
*/
public MockStatus verify() {
throw new AssertionFailedError("Invalid status");
}
}
|