This week I have revisted the downloading hyphenation-dictionary part and decided to seperate the code. So for the parts that are to be seperated are in the class Download Content. In order to facilitate the change a new bug - Bug 1280769 was created and made it to block the existing bug Bug 1276588.

Code:

@StringDef({KIND_FONT, KIND_HYPHENATION_DICTIONARY})
public static final String KIND_HYPHENATION_DICTIONARY = "hyphenation";


public boolean isHyphenationDictionary() {
        return KIND_HYPHENATION_DICTIONARY.equals(kind);
    }

    /**
     *Checks whether the content to be downloaded is a known content.
     *Currently it checks whether the type is "Asset Archive" and is of kind
     *"Font" or "Hyphenation Dictionary".
     */
    public boolean isKnownContent() {
        return ((isFont() || isHyphenationDictionary()) && isAssetArchive());
    }

Having added this code to the download content I have to make sure that the method works as intented. So I have written a few unit tests for the above method. Added the code to the Test Download Action.


/**
     * Scenario: If the file to be downloaded is of kind - "hyphenation"
     *
     * Verify that:
     * * isHyphenationDictionary returns true for a download content with kind "hyphenation"
     * * isHyphenationDictionary returns false for a download content with unknown/different kind like  "Font"
     */
    @Test
    public void testIsHyphenationDictionary() throws Exception {
        DownloadContent hyphenationContent = createHyphenationDictionary();
        Assert.assertTrue(hyphenationContent.isHyphenationDictionary());
        DownloadContent fontContent = createFont();
        Assert.assertFalse(fontContent.isHyphenationDictionary());
        DownloadContent unknownContent = createUnknownContent(1024L);
        Assert.assertFalse(unknownContent.isHyphenationDictionary());
    }

    /**
     * Scenario: If the content to be downloaded is known
     *
     * Verify that:
     * * isKnownContent returns true for a downloadable content with a known kind and type.
     * * isKnownContent returns false for a downloadable content with unknown kind and type.
     */
    @Test
    public void testIsKnownContent() throws Exception {
        DownloadContent fontContent = createFontWithSize(1024L);
        DownloadContent hyphenationContent = createHyphenationDictionaryWithSize(1024L);
        DownloadContent unknownContent = createUnknownContent(1024L);
        DownloadContent contentWithUnknownType = createContentWithoutType(1024L);

        Assert.assertTrue(fontContent.isKnownContent());
        Assert.assertTrue(hyphenationContent.isKnownContent());
        Assert.assertFalse(unknownContent.isKnownContent());
        Assert.assertFalse(contentWithUnknownType.isKnownContent());
    }

    private DownloadContent createUnknownContent(long size) {
        return new DownloadContentBuilder()
                .setSize(size)
                .build();
    }

    private DownloadContent createContentWithoutType(long size) {
        return new DownloadContentBuilder()
                .setKind(DownloadContent.KIND_HYPHENATION_DICTIONARY)
                .setSize(size)
                .build();
    }

    private DownloadContent createFont() {
        return createFontWithSize(102400L);
    }

    private DownloadContent createFontWithSize(long size) {
        return new DownloadContentBuilder()
                .setKind(DownloadContent.KIND_FONT)
                .setType(DownloadContent.TYPE_ASSET_ARCHIVE)
                .setSize(size)
                .build();
    }

    private DownloadContent createHyphenationDictionary() {
        return createHyphenationDictionaryWithSize(102400L);
    }

    private DownloadContent createHyphenationDictionaryWithSize(long size) {
        return new DownloadContentBuilder()
                .setKind(DownloadContent.KIND_HYPHENATION_DICTIONARY)
                .setType(DownloadContent.TYPE_ASSET_ARCHIVE)
                .setSize(size)
                .build();
    }

The above test methods are used to determine whether the downloading content is known. Currently we support the download of “Fonts” and “Hyphenation-Dictionary”. These files are classified as “Known Content”.