Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed May 28, 2024
1 parent 043f1e0 commit 561b0f3
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/test/java/org/apache/commons/net/tftp/TFTPTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
*/
package org.apache.commons.net.tftp;

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;

import junit.framework.TestCase;

Expand All @@ -38,7 +41,7 @@ public class TFTPTest extends TestCase {
private static final String FILE_PREFIX = "tftp-";
private static final File[] FILES = new File[8];

static int testsLeftToRun = 6;
static int testsLeftToRun = 9; // TODO Nasty hack.

// only want to do this once...
static {
Expand Down Expand Up @@ -111,6 +114,18 @@ public void testASCIIUploads() throws Exception {
}
}

public void testDiscardPackets() {
try (TFTP tftp = new TFTP()) {
assertThrows(NullPointerException.class, tftp::discardPackets);
}
}

public void testSend() {
try (TFTP tftp = new TFTP()) {
assertThrows(NullPointerException.class, () -> tftp.send(new TFTPDataPacket(InetAddress.getLocalHost(), 0, 0, new byte[0])));
}
}

private void testDownload(final int mode, final File file) throws IOException {
// Create our TFTP instance to handle the file transfer.
try (TFTPClient tftp = new TFTPClient()) {
Expand All @@ -134,6 +149,11 @@ private void testDownload(final int mode, final File file) throws IOException {
out.delete();
}
}

public void testGetModeName() {
assertNotNull(TFTP.getModeName(0));
assertNotNull(TFTP.getModeName(1));
}

public void testHugeDownloads() throws Exception {
// test with the smaller FILES
Expand Down

0 comments on commit 561b0f3

Please sign in to comment.