-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlTest.java
More file actions
57 lines (45 loc) · 1.97 KB
/
HtmlTest.java
File metadata and controls
57 lines (45 loc) · 1.97 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
package httpserver.file;
import org.junit.Test;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import static httpserver.file.FileHelpers.tempDir;
import static httpserver.file.FileHelpers.tempDirOptions;
import static httpserver.file.FileHelpers.tempFileOptions;
import static org.junit.Assert.*;
public class HtmlTest {
private final Path root;
private final Path fullDirPath;
private final Path fullFilePath;
private final Html html;
public HtmlTest() throws IOException {
root = tempDir();
fullDirPath = tempDirOptions(root);
fullFilePath = tempFileOptions(root, "aaa", "temp");
html = new Html();
}
@Test
public void makesHrefStringFromRootPathAndFullFilePath() throws Exception {
Path root = Paths.get("/Users", "example", "public");
Path fullFilePath = Paths.get("/Users", "example", "public", "example.txt");
assertEquals("example.txt", html.hrefString(root, fullFilePath));
}
@Test
public void makesHrefStringFromRootPathAndDirPath() throws Exception {
String expected = fullDirPath.toString().substring(root.toString().length() + 1) + "/";
assertEquals(expected, html.hrefString(root, fullDirPath));
}
@Test
public void makesHtmlLinkFromRootPathAndDirPath() throws Exception {
String expectedFilePath = fullFilePath.toString()
.substring(root.toString().length() + 1);
String expectedDirPath = fullDirPath.toString()
.substring(root.toString().length() + 1) + "/";
String expectedFileLink = "<div><a href=\"/" + expectedFilePath +
"\">/" + expectedFilePath + "</a></div>";
String expectedDirLink = "<div><a href=\"/" + expectedDirPath +
"\">/" + expectedDirPath + "</a></div>";
assertEquals(expectedFileLink, html.linkString(root, fullFilePath));
assertEquals(expectedDirLink, html.linkString(root, fullDirPath));
}
}