-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReliableNetworkTests.java
More file actions
64 lines (50 loc) · 1.87 KB
/
ReliableNetworkTests.java
File metadata and controls
64 lines (50 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.Assert.*;
public class ReliableNetworkTests {
private static final Integer PORT_RECEIVE = 2000;
@Before
public void setupFileReceiver() {
new Thread(new Runnable() {
@Override
public void run() {
try {
FileReceiver fileReceiver = new FileReceiver(PORT_RECEIVE);
fileReceiver.receiveFile();
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
@Test
public void testTransferSmallImage() throws Exception {
FileSender fileSender = new FileSender("doge.jpg", "localhost", PORT_RECEIVE.toString(), "doge-copy.jpg");
fileSender.sendFile();
Checksum inspector = new Checksum();
inspector.setInputFile("doge.jpg");
long originalChecksum = inspector.getChecksum();
inspector.setInputFile("doge-copy.jpg");
long cloneChecksum = inspector.getChecksum();
assertEquals(originalChecksum, cloneChecksum);
Path path = Paths.get("doge-copy.jpg");
Files.delete(path);
}
@Test
public void testTransferLargeImage() throws Exception {
FileSender fileSender = new FileSender("rc.jpg", "localhost", PORT_RECEIVE.toString(), "rc-copy.jpg");
fileSender.sendFile();
Checksum inspector = new Checksum();
inspector.setInputFile("rc.jpg");
long originalChecksum = inspector.getChecksum();
inspector.setInputFile("rc-copy.jpg");
long cloneChecksum = inspector.getChecksum();
assertEquals(originalChecksum, cloneChecksum);
Path path = Paths.get("rc-copy.jpg");
Files.delete(path);
}
}