class DownloadInfo implements Parcelable, Comparable<DownloadInfo> {

    public void setNumPieces(int numPieces)
    {
        if (numPieces <= 0)
            throw new IllegalArgumentException("Piece number can't be less or equal zero");

        if (!partialSupport && numPieces > 1)
            throw new IllegalStateException("The download doesn't support partial download");

        if ((totalBytes <= 0 && numPieces != 1) || (totalBytes > 0 && totalBytes < numPieces))
            throw new IllegalStateException("The number of pieces can't be more than the number of total bytes");

        this.numPieces = numPieces;
    }

}

class DownloadInfoTest {

    private DownloadInfo info;

    @Test
    public void testSetNumPieces()
    {

        try {
            info.setNumPieces(0);
            fail("Zero pieces test failed");
        } catch (IllegalArgumentException e) { }

        info.partialSupport = false;
        try {
            info.setNumPieces(3);
            fail("Partial support test failed");
        } catch (IllegalStateException e) { }

        info.partialSupport = true;
        info.totalBytes = -1;
        try {
            info.setNumPieces(3);
            fail("Multipart with unavailable size test failed");
        } catch (IllegalStateException e) { }

        info.totalBytes = 0;
        try {
            info.setNumPieces(3);
            fail("Multipart with zero size test failed");
        } catch (IllegalStateException e) { }

        info.totalBytes = 2;
        try {
            info.setNumPieces(3);
            fail("Size less than pieces test failed");
        } catch (IllegalStateException e) { }
    }

}