Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace SinkHandler by mocking object and improve test design #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.mockito.Mockito;
import org.mockito.ArgumentCaptor;
import static org.mockito.Mockito.*;

@RunWith(Parameterized.class)
public class ReactorTest {
Expand Down Expand Up @@ -385,19 +388,6 @@ public void checkNoVhost() throws IOException {
}


private static class SinkHandler extends BaseHandler {
protected int received = 0;

@Override
public void onDelivery(Event event) {
Delivery dlv = event.getDelivery();
if (!dlv.isPartial()) {
dlv.settle();
++received;
}
}
}

private static class SourceHandler extends BaseHandler {
private int remaining;

Expand Down Expand Up @@ -446,15 +436,28 @@ private void transfer(int count, int window) throws IOException {
// XXX: a window of 1 doesn't work unless the flowcontroller is
// added after the thing that settles the delivery
sh.add(new FlowController(window));
SinkHandler snk = new SinkHandler();
// Create variables for tracking behaviors of mock object
int[] snkReceived = new int[] { 0 };
// Construct mock object
BaseHandler snk = spy(BaseHandler.class);
// Method Stubs
doAnswer((stubInvo) -> {
Event event = stubInvo.getArgument(0);
Delivery dlv = event.getDelivery();
if (!dlv.isPartial()) {
dlv.settle();
++snkReceived[0];
}
return null;
}).when(snk).onDelivery(any(Event.class));
sh.add(snk);

SourceHandler src = new SourceHandler(count);
reactor.connectionToHost("127.0.0.1", ((AcceptorImpl)acceptor).getPortNumber(),
src);
reactor.run();
reactor.free();
assertEquals("Did not receive the expected number of messages", count, snk.received);
assertEquals("Did not receive the expected number of messages", count, snkReceived[0]);
checkForLeaks();
}

Expand Down