Allow customisation of the behaviour
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/trunk@1782409 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/org/apache/commons/net/tftp/TFTPServer.java b/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
index 2a819a1..fe0dd74 100644
--- a/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
+++ b/src/test/java/org/apache/commons/net/tftp/TFTPServer.java
@@ -461,7 +461,7 @@
{
try
{
- transferTftp_ = new TFTP();
+ transferTftp_ = newTFTP();
transferTftp_.beginBufferedOps();
transferTftp_.setDefaultTimeout(socketTimeout_);
@@ -575,7 +575,7 @@
lastSentData = new TFTPDataPacket(trrp.getAddress(), trrp.getPort(), block,
temp, 0, readLength);
- transferTftp_.bufferedSend(lastSentData);
+ sendData(transferTftp_, lastSentData); // send the data
}
answer = null;
@@ -716,7 +716,7 @@
}
TFTPAckPacket lastSentAck = new TFTPAckPacket(twrp.getAddress(), twrp.getPort(), 0);
- transferTftp_.bufferedSend(lastSentAck);
+ sendData(transferTftp_, lastSentAck); // send the data
while (true)
{
@@ -791,7 +791,7 @@
}
lastSentAck = new TFTPAckPacket(twrp.getAddress(), twrp.getPort(), block);
- transferTftp_.bufferedSend(lastSentAck);
+ sendData(transferTftp_, lastSentAck); // send the data
if (dataLength < TFTPDataPacket.MAX_DATA_LENGTH)
{
// end of stream signal - The tranfer is complete.
@@ -946,4 +946,18 @@
{
this.logError_ = logError;
}
+
+ /*
+ * Allow test code to customise the TFTP instance
+ */
+ TFTP newTFTP() {
+ return new TFTP();
+ }
+
+ /*
+ * Also allow customisation of sending data/ack so can generate errors if needed
+ */
+ void sendData(TFTP tftp, TFTPPacket data) throws IOException {
+ tftp.bufferedSend(data);
+ }
}