下面列出了怎么用org.junit.experimental.theories.suppliers.TestedOn的API类实例代码及写法,或者点击链接到github查看源代码。
@Theory( nullsAccepted = false )
public void appendedDoubleWithPrecisionParsesAsItselfWithTolerance( final Double value,
@TestedOn( ints = { 0, 1, 2, 3, 10, 16, 19, 20 } )
final int digits ) {
final ByteBuffer buffer = ByteBuffer.allocate( 50 );
BufferFormatter.append( buffer, value, digits );
final String formatted = BufferFormatterTest.toString( buffer );
final double parsedValue = Double.parseDouble( formatted );
assertThat(
".append(" + value + "," + digits + ") -> [" + formatted + "] -> [" + parsedValue + "]",
parsedValue,
closeTo( value, tolerance( digits ) )
);
}
@Theory( nullsAccepted = false )
public void appendedDoubleWithPrecisionParsesAsItselfWithToleranceCB( final Double value,
@TestedOn( ints = { 0, 1, 2, 3, 10, 16, 19, 20 } )
final int digits ) {
final CharBuffer buffer = CharBuffer.allocate( 50 );
BufferFormatter.append( buffer, value, digits );
final String formatted = BufferFormatterTest.toString( buffer );
final double parsedValue = Double.parseDouble( formatted );
assertThat(
".append(" + value + "," + digits + ") -> [" + formatted + "] -> [" + parsedValue + "]",
parsedValue,
closeTo( value, tolerance( digits ) )
);
}
@Theory
public void testStopDeploymentGroup(
@TestedOn(ints = { 0, 1 }) final int dgExistsInt,
@TestedOn(ints = { 0, 1 }) final int tasksExistInt,
@TestedOn(ints = { 0, 1 }) final int tasksExistWhenCommittingInt
) throws Exception {
final boolean dgExists = dgExistsInt != 0;
final boolean tasksExist = tasksExistInt != 0;
final boolean tasksExistWhenCommitting = tasksExistWhenCommittingInt != 0;
// To be able to simulate triggering the race condition in stopDeploymentGroup we need to do
// some mocking, relying on that the implementation uses client.exists() to check for the
// presence of tasks.
final ZooKeeperClient client = spy(this.client);
when(client.exists(Paths.statusDeploymentGroupTasks(GROUP_NAME)))
.thenReturn(tasksExist ? mock(Stat.class) : null);
final ZooKeeperMasterModel masterModel = newMasterModel(client);
if (dgExists) {
final DeploymentGroup dg = DeploymentGroup.newBuilder()
.setName(GROUP_NAME)
.build();
masterModel.addDeploymentGroup(dg);
}
if (tasksExistWhenCommitting) {
client.ensurePath(Paths.statusDeploymentGroupTasks());
client.create(Paths.statusDeploymentGroupTasks(GROUP_NAME));
}
if (!dgExists) {
exception.expect(DeploymentGroupDoesNotExistException.class);
} else if (tasksExist != tasksExistWhenCommitting) {
exception.expect(HeliosRuntimeException.class);
}
masterModel.stopDeploymentGroup(GROUP_NAME);
// Verify that the state in ZK is correct:
// * tasks are not present
// * the status is set to FAILED
//
// When checking for the existence of the tasks make sure we use the client that doesn't have
// the exists() method mocked out!
assertNull(this.client.exists(Paths.statusDeploymentGroupTasks(GROUP_NAME)));
final DeploymentGroupStatus status = masterModel.getDeploymentGroupStatus(GROUP_NAME);
assertEquals(FAILED, status.getState());
}
@Theory
public void testRemoveShapeIntKO(@SetShapeData final SetShapesProp shape, @TestedOn(ints = {-2, -1, 1, 2}) final int value) {
shape.getShapes().add(sh1);
shape.removeShape(value);
}
@Theory
public void testGetPtAt(@RectangularData final RectangularShape shape, @TestedOn(ints = {-1, 0, 1, 2, 3}) final int i) {
assertNotNull(shape.getPtAt(i));
}
@Theory
public void testGetPtAtKO(@RectangularData final RectangularShape shape, @TestedOn(ints = {-2, 4}) final int i) {
assertNull(shape.getPtAt(i));
}
@Theory
public void testGetSetInterval(@TestedOn(ints = {1, 10}) final int value) {
shape.setInterval(value);
assertEquals(value, shape.getInterval());
}
@Theory
public void testGetFirstCtrlPtAt(@CtrlShapeData final ControlPointShape sh, @TestedOn(ints = {0, 1, -1}) final int value) {
assertNotNull(sh.getFirstCtrlPtAt(value));
}
@Theory
public void testGetFirstCtrlPtAtKO(@CtrlShapeData final ControlPointShape sh, @TestedOn(ints = {-2, 2}) final int value) {
assertNull(sh.getFirstCtrlPtAt(value));
}
@Theory
public void testGetSecondCtrlPtAt(@CtrlShapeData final ControlPointShape sh, @TestedOn(ints = {0, 1, -1}) final int value) {
assertNotNull(sh.getSecondCtrlPtAt(value));
}
@Theory
public void testUpdateSecondControlPoints(@CtrlShapeData final ControlPointShape sh, @TestedOn(ints = {-2, 2}) final int value) {
assertNull(sh.getSecondCtrlPtAt(value));
}
@Theory
public void testSetXFirstCtrlPt(@CtrlShapeData final ControlPointShape sh, @TestedOn(ints = {0, 1, -1}) final int index) {
sh.setXFirstCtrlPt(33d, index);
assertEqualsDouble(33d, sh.getFirstCtrlPtAt(index).getX());
}
@Theory
public void testSetYFirstCtrlPt(@CtrlShapeData final ControlPointShape sh, @TestedOn(ints = {0, 1, -1}) final int index) {
sh.setYFirstCtrlPt(33d, index);
assertEqualsDouble(33d, sh.getFirstCtrlPtAt(index).getY());
}
@Theory
public void testSetXSecondCtrlPt(@CtrlShapeData final ControlPointShape sh, @TestedOn(ints = {0, 1, -1}) final int index) {
sh.setXSecondCtrlPt(33d, index);
assertEqualsDouble(33d, sh.getSecondCtrlPtAt(index).getX());
}
@Theory
public void testSetYSecondCtrlPt(@CtrlShapeData final ControlPointShape sh, @TestedOn(ints = {0, 1, -1}) final int index) {
sh.setYSecondCtrlPt(33d, index);
assertEqualsDouble(33d, sh.getSecondCtrlPtAt(index).getY());
}
@Theory
public void testValidGetSetNbPlottedPoints(@TestedOn(ints = {2, 10, 200}) final int value) {
shape.setNbPlottedPoints(value);
assertEquals(value, shape.getNbPlottedPoints());
}
@Theory
public void testValidGetSetNbPlottedPointsKO(@TestedOn(ints = {1, 0, -1}) final int value) {
shape.setNbPlottedPoints(10);
shape.setNbPlottedPoints(value);
assertEquals(10, shape.getNbPlottedPoints());
}
@Theory
public void testSetPoint2KO2(@ModifPtShapeData final ModifiablePointsShape shape,
@TestedOn(ints = {-2, 10}) final int value) {
assertFalse(shape.setPoint(0, 0, value));
}
@Theory
public void testGetSetLabelsSize(@StdGridData final StandardGrid shape, @TestedOn(ints = {0, 1, 10}) final int value) {
shape.setLabelsSize(value);
assertEquals(value, shape.getLabelsSize());
}
@Theory
public void testGetSetGridDots(@TestedOn(ints = {0, 1, 10}) final int value) {
shape.setGridDots(value);
assertEquals(value, shape.getGridDots());
}
@Theory
public void testGetSetSubGridDiv(@TestedOn(ints = {0, 1, 10}) final int value) {
shape.setSubGridDiv(value);
assertEquals(value, shape.getSubGridDiv());
}
@Theory
public void testGetSetSubGridDots(@TestedOn(ints = {0, 1, 10}) final int value) {
shape.setSubGridDots(value);
assertEquals(value, shape.getSubGridDots());
}