@@ -0,0 +1,3404 @@
+package com.justjournal.services;%0A%0Aimport com.justjournal.model.User;%0Aimport com.justjournal.model.UserLink;%0Aimport com.justjournal.model.api.UserLinkTo;%0Aimport com.justjournal.repository.UserLinkRepository;%0Aimport com.justjournal.repository.UserRepository;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.InjectMocks;%0Aimport org.mockito.Mock;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0A%0Aimport java.util.Collections;%0Aimport java.util.List;%0Aimport java.util.Optional;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.mockito.ArgumentMatchers.any;%0Aimport static org.mockito.ArgumentMatchers.anyInt;%0Aimport static org.mockito.ArgumentMatchers.anyString;%0Aimport static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0A/**%0A * @author Lucas Holt%0A */%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class UserLinkServiceTests %7B%0A%0A    @Mock%0A    private UserLinkRepository userLinkRepository;%0A%0A    @Mock%0A    private UserRepository userRepository;%0A%0A    @InjectMocks%0A    private UserLinkService userLinkService;%0A%0A    @Test%0A    public void testCreate() %7B%0A        UserLinkTo link = UserLinkTo.builder()%0A                .id(1)%0A                .title(%22foo%22)%0A                .uri(%22http://mysite.com%22)%0A                .userId(1)%0A                .build();%0A%0A        UserLink item = UserLink.builder()%0A                .id(1)%0A                .title(%22foo%22)%0A                .uri(%22http://mysite.com%22)%0A                .user(new User())%0A                .build();%0A%0A        when(userLinkRepository.save(any())).thenReturn(item);%0A        UserLinkTo result = userLinkService.create(link);%0A        assertNotNull(result);%0A        verify(userLinkRepository, times(1)).save(any(UserLink.class));%0A    %7D%0A%0A    @Test%0A    public void testGet() %7B%0A        UserLink item = UserLink.builder()%0A                .id(1)%0A                .title(%22foo%22)%0A                .uri(%22http://mysite.com%22)%0A                .user(new User())%0A                .build();%0A        when(userLinkRepository.findById(anyInt())).thenReturn(Optional.of(item));%0A%0A        Optional%3CUserLinkTo%3E result = userLinkService.get(1);%0A        assertTrue(result.isPresent());%0A        assertEquals(1, result.get().getId());%0A        assertEquals(%22foo%22, result.get().getTitle());%0A        assertEquals(%22http://mysite.com%22, result.get().getUri());%0A        verify(userLinkRepository, times(1)).findById(1);%0A    %7D%0A%0A    @Test%0A    public void testGetByUser() %7B%0A        UserLink item = UserLink.builder()%0A                .id(1)%0A                .title(%22foo%22)%0A                .uri(%22http://mysite.com%22)%0A                .user(new User())%0A                .build();%0A        when(userLinkRepository.findByUsernameOrderByTitleTitleAsc(anyString())).thenReturn(Collections.singletonList(item));%0A%0A        List%3CUserLinkTo%3E result = userLinkService.getByUser(%22user%22);%0A        assertNotNull(result);%0A        assertEquals(1, result.get(0).getId());%0A        assertEquals(%22foo%22, result.get(0).getTitle());%0A        assertEquals(%22http://mysite.com%22, result.get(0).getUri());%0A        verify(userLinkRepository, times(1)).findByUsernameOrderByTitleTitleAsc(anyString());%0A    %7D%0A%0A    @Test%0A    public void testDelete() %7B%0A        userLinkService.delete(1);%0A        verify(userLinkRepository, times(1)).deleteById(anyInt());%0A    %7D%0A%7D%0A

add userlink service tests