Skip to content

Instantly share code, notes, and snippets.

@alecmce
Created November 29, 2012 02:26
Show Gist options
  • Save alecmce/4166387 to your computer and use it in GitHub Desktop.
Save alecmce/4166387 to your computer and use it in GitHub Desktop.
My first pass at an IDataOutput/IDataInput mockolate decorator
import flash.utils.ByteArray;
import mockolate.decorations.Decorator;
import mockolate.ingredients.MockingCouverture;
import mockolate.ingredients.Mockolate;
import mockolate.ingredients.answers.ReturnsCallAnswer;
class DataIODecorator extends Decorator
{
private const data:ByteArray = new ByteArray();
public function DataIODecorator(mockolate:Mockolate)
{
super(mockolate);
initialize();
}
private function initialize():void
{
var stub:MockingCouverture = mocker.stub();
stub.method("bytesAvailable").answers(new ReturnsCallAnswer(getBytesAvailable));
stub.method("readInt").answers(new ReturnsCallAnswer(data.readInt));
stub.method("readUnsignedByte").answers(new ReturnsCallAnswer(data.readUnsignedByte));
stub.method("readByte").answers(new ReturnsCallAnswer(data.readByte));
stub.method("writeBoolean").answers(new ReturnsCallAnswer(data.writeBoolean));
stub.method("writeByte").answers(new ReturnsCallAnswer(data.writeByte));
stub.method("writeBytes").answers(new ReturnsCallAnswer(data.writeBytes));
stub.method("writeDouble").answers(new ReturnsCallAnswer(data.writeDouble));
stub.method("writeFloat").answers(new ReturnsCallAnswer(data.writeFloat));
stub.method("writeInt").answers(new ReturnsCallAnswer(data.writeInt));
}
private function getBytesAvailable():int
{
return data.bytesAvailable;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment