@Test
public void testReplyReceived() {

	// Just to setup some variables
	Field response;
	Field receivedReplies;
	Field reqId;
	Field replyQuorum;
	Field replies;
	Field requestType;
	try {
		response = ServiceProxy.class.getDeclaredField("response");
		response.setAccessible(true);
		receivedReplies = ServiceProxy.class.getDeclaredField("receivedReplies");
		receivedReplies.setAccessible(true);
		reqId = ServiceProxy.class.getDeclaredField("reqId");
		reqId.setAccessible(true);
		replyQuorum = ServiceProxy.class.getDeclaredField("replyQuorum");
		replyQuorum.setAccessible(true);
		replies = ServiceProxy.class.getDeclaredField("replies");
		replies.setAccessible(true);
		requestType = ServiceProxy.class.getDeclaredField("requestType");
		requestType.setAccessible(true);
		try {
			// Test if a the method decides correctly when three correct
			// replies are received in sequence. The request are ordered
			TOMMessage[] initReplies = new TOMMessage[4];
			receivedReplies.set(proxy, 0);
			reqId.setInt(proxy, 1);
			replyQuorum.setInt(proxy, 3);
			replies.set(proxy, initReplies);
			requestType.set(proxy, TOMMessageType.ORDERED_REQUEST);
			response.set(proxy, null);
			TOMMessage msg = new TOMMessage(0, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(1, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(2, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			TOMMessage reply = (TOMMessage) response.get(proxy);
			Assert.assertEquals("response1", new String(reply.getContent()));
			// Test if a the method decides correctly when the replies are
			// correct, correct, wrong and correct, in that order. The requests
			// are ordered
			initReplies = new TOMMessage[4];
			receivedReplies.set(proxy, 0);
			reqId.setInt(proxy, 1);
			replyQuorum.setInt(proxy, 3);
			replies.set(proxy, initReplies);
			requestType.set(proxy, TOMMessageType.ORDERED_REQUEST);
			response.set(proxy, null);
			msg = new TOMMessage(0, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(1, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(2, 1, 1, "response2".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(3, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			reply = (TOMMessage) response.get(proxy);
			Assert.assertEquals("response1", new String(reply.getContent()));
			// Negative test, to verify if the method doesn't decide when the values
			// doesn't match as a reply quorum. The values are 2 response1 and 2 response2
			initReplies = new TOMMessage[4];
			receivedReplies.set(proxy, 0);
			reqId.setInt(proxy, 1);
			replyQuorum.setInt(proxy, 3);
			replies.set(proxy, initReplies);
			requestType.set(proxy, TOMMessageType.ORDERED_REQUEST);
			response.set(proxy, null);
			msg = new TOMMessage(0, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(1, 1, 1, "response1".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(2, 1, 1, "response2".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(3, 1, 1, "response2".getBytes(), 0, TOMMessageType.ORDERED_REQUEST);
			proxy.replyReceived(msg);
			reply = (TOMMessage) response.get(proxy);
			Assert.assertNull(reply);
			Assert.assertEquals(-1, reqId.get(proxy));
			// Test replyReceived for correct readonly messages
			initReplies = new TOMMessage[4];
			receivedReplies.set(proxy, 0);
			reqId.setInt(proxy, 1);
			replies.set(proxy, initReplies);
			requestType.set(proxy, TOMMessageType.UNORDERED_REQUEST);
			response.set(proxy, null);
			msg = new TOMMessage(0, 1, 1, "response1".getBytes(), 0, TOMMessageType.UNORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(1, 1, 1, "response1".getBytes(), 0, TOMMessageType.UNORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(2, 1, 1, "response1".getBytes(), 0, TOMMessageType.UNORDERED_REQUEST);
			proxy.replyReceived(msg);
			reply = (TOMMessage) response.get(proxy);
			Assert.assertEquals("response1", new String(reply.getContent()));
			// Test if the method fails for the first diverging readonly reply
			receivedReplies.set(proxy, 0);
			reqId.setInt(proxy, 1);
			replies.set(proxy, initReplies);
			requestType.set(proxy, TOMMessageType.UNORDERED_REQUEST);
			response.set(proxy, null);
			msg = new TOMMessage(0, 1, 1, "response1".getBytes(), 0, TOMMessageType.UNORDERED_REQUEST);
			proxy.replyReceived(msg);
			msg = new TOMMessage(1, 1, 1, "response2".getBytes(), 0, TOMMessageType.UNORDERED_REQUEST);
			proxy.replyReceived(msg);
			reply = (TOMMessage) response.get(proxy);
			Assert.assertEquals(-1, reqId.get(proxy));
		} catch (IllegalArgumentException | IllegalAccessException e) {
			e.printStackTrace();
		}
	} catch (NoSuchFieldException e) {
		e.printStackTrace();
	} catch (SecurityException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}