Skip to content

Implement your own Shark ASAP application (4 of 5)

Thomas Schwotzer edited this page Jan 4, 2022 · 16 revisions

Step 4: Implement and test

There are German video explaining a) testing with ASAP and b) adding your code to an Android app.

Software must be tested. Full stop. No exceptions. Fortunately, we can follow / copy / adopt existing tests. We assume, you implement a SharkComponent. Good choice! Have a look into our test case in project SharkPeer. That test case is explained in more detail in this section.

Setup a Shark component

Setting up your component is not our business, though. There is a only a sketch of a real component in our tests case. That is the setupComponent() method:

private YourComponent setupComponent(SharkPeer sharkPeer) throws SharkException {
    // give peer anything that is needed to create your component
    sharkPeer.addComponent(new YourComponentFactory(), YourComponent.class);
    // force peer to create your component
    YourComponent yourComponent = (YourComponent) sharkPeer.getComponent(YourComponent.class);
    // return the object reference of your component
    return yourComponent;
}

A SharkPeer object is before setting up your component. This object comes as parameter. Remaining lines are already explained in a previous section. You add your component to the peer by creating a factory object. You can now force the peer to create an object of your component. This method simply returns this object reference.

Pretty simple. No hidden tricks.

Setup a Shark peer

Have a look at our sendAMessage() test case.

Clone this wiki locally