Ver código fonte

GenerateRandomNumberValues

Andrew Grant 4 meses atrás
pai
commit
27dfa21bfa

+ 5 - 0
src/test/java/scot/carricksoftware/grantswriter/GenerateRandomNumberValues.java

@@ -19,5 +19,10 @@ public class GenerateRandomNumberValues {
         return rand.nextLong();
     }
 
+    @SuppressWarnings("SameReturnValue")
+    public static String GetRandomString() {
+        return "Andrew";
+    }
+
 
 }

+ 18 - 0
src/test/java/scot/carricksoftware/grantswriter/controllers/FilesControllerTest.java

@@ -14,6 +14,10 @@ import org.springframework.ui.Model;
 import scot.carricksoftware.grantswriter.files.WriterFiles;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static scot.carricksoftware.grantswriter.GenerateRandomNumberValues.GetRandomString;
 
 @ExtendWith(MockitoExtension.class)
 class FilesControllerTest {
@@ -35,4 +39,18 @@ class FilesControllerTest {
     void filesReturnsTheCorrectPageTest() {
         assertEquals("files", controller.getFiles(modelMock));
     }
+
+    @Test
+    void filesInitIfNullTest() {
+        when(writerFilesMock.getLatexFileName()).thenReturn(null);
+        controller.getFiles(modelMock);
+        verify(writerFilesMock).init();
+    }
+
+    @Test
+    void filesDoesNotInitIfNotNullTest() {
+        when(writerFilesMock.getLatexFileName()).thenReturn(GetRandomString());
+        controller.getFiles(modelMock);
+        verify(writerFilesMock, times(0)).init();
+    }
 }