<commit_before>package com.github.vergnes.albumindexer.rss;

/**
 * Created by denis.vergnes on 21/08/2015.
 */
public class RssAlbumFetcherTaskTest {

    
}<commit_msg>add unit test<commit_after>package com.github.vergnes.albumindexer.rss;

import com.github.vergnes.albumindexer.domain.Album;
import com.rometools.fetcher.FeedFetcher;
import com.rometools.rome.feed.synd.SyndEntry;
import com.rometools.rome.feed.synd.SyndFeed;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.Arrays;
import java.util.Optional;
import java.util.function.Consumer;

import static org.mockito.Matchers.any;
import static org.mockito.Mockito.*;

/**
 * Created by denis.vergnes on 21/08/2015.
 */
@RunWith(MockitoJUnitRunner.class)
public class RssAlbumFetcherTaskTest {

    @Mock
    private RssAlbumParser parser;

    @Mock
    private FeedFetcher fetcher;

    @Mock
    private Consumer<Album> consumer;

    @InjectMocks
    private RssAlbumFetcherTask task;

    @Test
    public void should_retrieve_albums() throws Exception {
        SyndFeed syndFeed = mock(SyndFeed.class);
        SyndEntry entry1 = mock(SyndEntry.class);
        SyndEntry entry2 = mock(SyndEntry.class);
        SyndEntry entry3 = mock(SyndEntry.class);
        when(syndFeed.getEntries()).thenReturn(Arrays.asList(entry1, entry2, entry3));

        when(fetcher.retrieveFeed(null)).thenReturn(syndFeed);

        Album album1 = mock(Album.class);
        Album album2 = mock(Album.class);
        when(parser.parse(any(SyndEntry.class))).thenReturn(Optional.of(album1), Optional.empty(), Optional.of(album2));

        task.fetchAlbums();

        verify(consumer).accept(album1);
        verify(consumer).accept(album2);
    }

}
{'fraction_non_alphanumeric': 0.1143951833607006, 'fraction_numerical': 0.01532567049808429, 'mean_word_length': 3.953929539295393, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6081063', 'n_tokens_mistral': 631, 'n_tokens_neox': 602, 'n_words': 103}