|
| 1 | +package httpserver; |
| 2 | + |
| 3 | +import httpserver.file.PathExaminerSpy; |
| 4 | +import org.junit.Test; |
| 5 | + |
| 6 | +import java.nio.file.Path; |
| 7 | +import java.nio.file.Paths; |
| 8 | + |
| 9 | +import static org.junit.Assert.*; |
| 10 | + |
| 11 | +public class ServerFactoryTest { |
| 12 | + |
| 13 | + private final Path spyGetPathResult; |
| 14 | + private PathExaminerSpy pathExaminerSpy; |
| 15 | + private ServerSocketFactorySpy serverSocketFactorySpy; |
| 16 | + private ServerFactory serverFactory; |
| 17 | + private String fileDirectory; |
| 18 | + |
| 19 | + public ServerFactoryTest() { |
| 20 | + spyGetPathResult = Paths.get("example, public"); |
| 21 | + pathExaminerSpy = new PathExaminerSpy(spyGetPathResult); |
| 22 | + serverSocketFactorySpy = new ServerSocketFactorySpy(); |
| 23 | + serverFactory = new ServerFactory(pathExaminerSpy, |
| 24 | + serverSocketFactorySpy); |
| 25 | + fileDirectory = "/example/public/"; |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void callsGetPathOnPathExaminerWithFileDirectory() throws Exception { |
| 30 | + serverFactory.makeServer(5000, fileDirectory); |
| 31 | + |
| 32 | + assertEquals(fileDirectory, pathExaminerSpy.getPathCalledWith); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void callsPathExaminerConcatenateWithResultOfGetPathAndLogs() throws Exception { |
| 37 | + serverFactory.makeServer(5000, fileDirectory); |
| 38 | + |
| 39 | + assertEquals(spyGetPathResult, pathExaminerSpy.concatenateCalledWith1); |
| 40 | + assertEquals("logs", pathExaminerSpy.concatenateCalledWith2); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void callsNewServerSocketOnServerSocketFactoryWithPort() throws Exception { |
| 45 | + serverFactory.makeServer(5000, fileDirectory); |
| 46 | + |
| 47 | + assertEquals(5000, serverSocketFactorySpy.newServerSocketCalledWith); |
| 48 | + } |
| 49 | +} |
0 commit comments