src/test/java/za/co/grindrodbank/dokuti/document/DocumentControllerUnitTests.java
@Test
    public void givenDocument_whenFavoriteDocument_thenReturnFavouriteDocumnet2() throws Exception {

        UUID documentId = UUID.randomUUID();
        UUID userId = UUID.randomUUID();

        DocumentEntity document = new DocumentEntity();
        document.setId(documentId);
        document.setContentType("text/plain");
        document.setDescription("Document Desc");
        document.setName("Document Name");
        document.setIsArchived(false);
        document.setDocumentVersions(new HashSet<>());
        document.setDocumentTags(new ArrayList<>());
        document.setDocumentPermissions(new ArrayList<>());
        document.setDocumentFavourites(null);

        Mockito.when(documentService.findById(documentId)).thenReturn(document);
        Mockito.when(databaseEntityToApiDataTranfserObjectMapperServiceImpl.mapDocumentEntityPageToDocumentPage(any())).thenCallRealMethod();
        Mockito.when(databaseEntityToApiDataTranfserObjectMapperServiceImpl.mapDocumentEntityToDocument(any())).thenCallRealMethod();
        Mockito.when(documentService.save(document)).thenReturn(document);
        
        PowerMockito.mockStatic(SecurityContextUtility.class);
        Mockito.when(SecurityContextUtility.getUserIdFromJwt()).thenReturn(userId.toString());        
        
        mvc.perform(post("/documents/" + documentId + "/favourite")
                      .contentType(MediaType.APPLICATION_JSON)
                      .characterEncoding("utf-8"))
                      .andExpect(status().is(200));
        assertTrue("should be one favorited doc now", document.getDocumentFavourites().size() == 1); 
        assertTrue("favorited user should match current user", userId.equals(document.getDocumentFavourites().get(0).getUserId())); 
    }
// this test similar above except setDocumentFavourites(null) instead of empty list
this test similar above except setDocumentFavourites(null) instead of empty list
this test similar above except setDocumentFavourites ( null ) instead of empty list
@Test
    public void givenDocument_whenFavoriteDocument_thenReturnFavouriteDocumnet2() throws Exception {
        UUID documentId = UUID.randomUUID();
        UUID userId = UUID.randomUUID();
        DocumentEntity document = new DocumentEntity();
        document.setId(documentId);
        document.setContentType("text/plain");
        document.setDescription("Document Desc");
        document.setName("Document Name");
        document.setIsArchived(false);
        document.setDocumentVersions(new HashSet<>());
        document.setDocumentTags(new ArrayList<>());
        document.setDocumentPermissions(new ArrayList<>());
        document.setDocumentFavourites(null);
        Mockito.when(documentService.findById(documentId)).thenReturn(document);
        Mockito.when(databaseEntityToApiDataTranfserObjectMapperServiceImpl.mapDocumentEntityPageToDocumentPage(any())).thenCallRealMethod();
        Mockito.when(databaseEntityToApiDataTranfserObjectMapperServiceImpl.mapDocumentEntityToDocument(any())).thenCallRealMethod();
        Mockito.when(documentService.save(document)).thenReturn(document);
        PowerMockito.mockStatic(SecurityContextUtility.class);
        Mockito.when(SecurityContextUtility.getUserIdFromJwt()).thenReturn(userId.toString());        
        mvc.perform(post("/documents/" + documentId + "/favourite")
                      .contentType(MediaType.APPLICATION_JSON)
                      .characterEncoding("utf-8"))
                      .andExpect(status().is(200));
        assertTrue("should be one favorited doc now", document.getDocumentFavourites().size() == 1); 
        assertTrue("favorited user should match current user", userId.equals(document.getDocumentFavourites().get(0).getUserId())); 
    }
@ Test public void givenDocument_whenFavoriteDocument_thenReturnFavouriteDocumnet2 ( ) throws Exception { UUID documentId = UUID . randomUUID ( ) ; UUID userId = UUID . randomUUID ( ) ; DocumentEntity document = new DocumentEntity ( ) ; document . setId ( documentId ) ; document . setContentType ( "text/plain" ) ; document . setDescription ( "Document Desc" ) ; document . setName ( "Document Name" ) ; document . setIsArchived ( false ) ; document . setDocumentVersions ( new HashSet < > ( ) ) ; document . setDocumentTags ( new ArrayList < > ( ) ) ; document . setDocumentPermissions ( new ArrayList < > ( ) ) ; document . setDocumentFavourites ( null ) ; Mockito . when ( documentService . findById ( documentId ) ) . thenReturn ( document ) ; Mockito . when ( databaseEntityToApiDataTranfserObjectMapperServiceImpl . mapDocumentEntityPageToDocumentPage ( any ( ) ) ) . thenCallRealMethod ( ) ; Mockito . when ( databaseEntityToApiDataTranfserObjectMapperServiceImpl . mapDocumentEntityToDocument ( any ( ) ) ) . thenCallRealMethod ( ) ; Mockito . when ( documentService . save ( document ) ) . thenReturn ( document ) ; PowerMockito . mockStatic ( SecurityContextUtility . class ) ; Mockito . when ( SecurityContextUtility . getUserIdFromJwt ( ) ) . thenReturn ( userId . toString ( ) ) ; mvc . perform ( post ( "/documents/" + documentId + "/favourite" ) . contentType ( MediaType . APPLICATION_JSON ) . characterEncoding ( "utf-8" ) ) . andExpect ( status ( ) . is ( 200 ) ) ; assertTrue ( "should be one favorited doc now" , document . getDocumentFavourites ( ) . size ( ) == 1 ) ; assertTrue ( "favorited user should match current user" , userId . equals ( document . getDocumentFavourites ( ) . get ( 0 ) . getUserId ( ) ) ) ; }
this test similar above except setDocumentFavourites(null) instead of empty list
this test similar above except setDocumentFavourites ( null ) instead of empty list