<commit_before>package lan.dk.podcastserver.service;

import lan.dk.podcastserver.entity.Item;
import lan.dk.podcastserver.entity.Podcast;
import org.junit.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Created by kevin on 16/07/15 for Podcast Server
 */
public class MimeTypeServiceTest {

    @Test
    public void should_get_mimeType_if_no_extension() {
        /* Given */ MimeTypeService mimeTypeService = new MimeTypeService();
        /* When */  String mimeType = mimeTypeService.getMimeType("");
        /* Then */  assertThat(mimeType).isEqualTo("application/octet-stream");
    }

    @Test
    public void should_get_mimetype_for_known_extension() {
        /* Given */ MimeTypeService mimeTypeService = new MimeTypeService();
        /* When */  String mimeType = mimeTypeService.getMimeType("webm");
        /* Then */  assertThat(mimeType).isEqualTo("video/webm");
    }

    @Test
    public void should_get_mimetype_for_unknown_extension() {
        /* Given */ MimeTypeService mimeTypeService = new MimeTypeService();
        /* When */  String mimeType = mimeTypeService.getMimeType("txt");
        /* Then */  assertThat(mimeType).isEqualTo("unknown/txt");
    }

    @Test
    public void should_get_extension_by_mimeType() {
        /* Given */
        MimeTypeService mimeTypeService = new MimeTypeService();
        Item item = new Item().setMimeType("audio/mp3");

        /* When */ String extension = mimeTypeService.getExtension(item);
        /* Then */ assertThat(extension).isEqualTo(".mp3");
    }

    @Test
    public void should_get_extension_by_Youtube() {
        /* Given */
        MimeTypeService mimeTypeService = new MimeTypeService();
        Item item = new Item().setPodcast(new Podcast().setType("Youtube")).setUrl("http://fake.com/foo/bar");

        /* When */ String extension = mimeTypeService.getExtension(item);
        /* Then */ assertThat(extension).isEqualTo(".mp4");
    }

    @Test
    public void should_get_extension_by_url() {
        /* Given */
        MimeTypeService mimeTypeService = new MimeTypeService();
        Item item = new Item()
                .setPodcast(new Podcast().setType("Other"))
                .setUrl("http://fake.com/foo/bar.mp4a");

        /* When */ String extension = mimeTypeService.getExtension(item);
        /* Then */ assertThat(extension).isEqualTo(".mp4a");
    }

    @Test
    public void should_get_mimeType_from_contentType_via_tika() throws URISyntaxException, IOException {
        /* Given */
        Path path = Paths.get(MimeTypeServiceTest.class.getResource("/remote/podcast/plain.text.txt").toURI());
        MimeTypeService mimeTypeService = new MimeTypeService();

        /* When */ String type = mimeTypeService.probeContentType(path);
        /* Then */ assertThat(type).isEqualTo("text/plain");
    }
}<commit_msg>test(service.mimeType): expand testing<commit_after>package lan.dk.podcastserver.service;

import lan.dk.podcastserver.entity.Item;
import lan.dk.podcastserver.entity.Podcast;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Created by kevin on 16/07/15 for Podcast Server
 */
public class MimeTypeServiceTest {

    MimeTypeService mimeTypeService;

    @Before
    public void beforeEach() {
        mimeTypeService = new MimeTypeService();
    }

    @Test
    public void should_get_mimeType_if_no_extension() {
        /* When */  String mimeType = mimeTypeService.getMimeType("");
        /* Then */  assertThat(mimeType).isEqualTo("application/octet-stream");
    }

    @Test
    public void should_get_mimetype_for_known_extension() {
        /* When */  String mimeType = mimeTypeService.getMimeType("webm");
        /* Then */  assertThat(mimeType).isEqualTo("video/webm");
    }

    @Test
    public void should_get_mimetype_for_unknown_extension() {
        /* When */  String mimeType = mimeTypeService.getMimeType("txt");
        /* Then */  assertThat(mimeType).isEqualTo("unknown/txt");
    }

    @Test
    public void should_get_extension_by_mimeType() {
        /* Given */
        Item item = new Item().setMimeType("audio/mp3");

        /* When */ String extension = mimeTypeService.getExtension(item);
        /* Then */ assertThat(extension).isEqualTo(".mp3");
    }

    @Test
    public void should_get_extension_by_Youtube() {
        /* Given */
        Item item = new Item().setPodcast(new Podcast().setType("Youtube")).setUrl("http://fake.com/foo/bar");

        /* When */ String extension = mimeTypeService.getExtension(item);
        /* Then */ assertThat(extension).isEqualTo(".mp4");
    }

    @Test
    public void should_get_extension_by_url() {
        /* Given */
        Item item = new Item()
                .setPodcast(new Podcast().setType("Other"))
                .setUrl("http://fake.com/foo/bar.mp4a");

        /* When */ String extension = mimeTypeService.getExtension(item);
        /* Then */ assertThat(extension).isEqualTo(".mp4a");
    }

    @Test
    public void should_get_mimeType_with_probeContentType() throws URISyntaxException, IOException {
        /* Given */
        Path path = Paths.get(MimeTypeServiceTest.class.getResource("/remote/podcast/plain.text.txt").toURI());

        /* When */ String type = mimeTypeService.probeContentType(path);
        /* Then */ assertThat(type).isEqualTo("text/plain");
    }
    
    @Test
    public void should_find_mimeType_from_inline_map() {
        /* Given */
        Path file = Paths.get("/", "root", "foo");

        /* When */
        String contentType = mimeTypeService.probeContentType(file);

        /* Then */
        assertThat(contentType).isEqualTo("application/octet-stream");
    }
}
{'fraction_non_alphanumeric': 0.13205020920502092, 'fraction_numerical': 0.0036820083682008366, 'mean_word_length': 2.970764119601329, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2653819', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1792, 'n_words': 312}