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; } DownloadInfo(@NonNull Uri dirPath,
                        @NonNull String url,
                        @NonNull String fileName); @Ignore  DownloadInfo(@NonNull Parcel source); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); void setNumPieces(int numPieces); int getNumPieces(); List<DownloadPiece> makePieces(); long pieceStartPos(@NonNull DownloadPiece piece); long pieceEndPos(@NonNull DownloadPiece piece); long getDownloadedBytes(@NonNull DownloadPiece piece); @Override int compareTo(@NonNull DownloadInfo another); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); static final int MIN_PIECES; static final int MAX_PIECES; static final int VISIBILITY_VISIBLE; static final int VISIBILITY_VISIBLE_NOTIFY_COMPLETED; static final int VISIBILITY_HIDDEN; static final int VISIBILITY_VISIBLE_NOTIFY_ONLY_COMPLETION; static final int MIN_RETRY_AFTER; static final int MAX_RETRY_AFTER; @PrimaryKey
    @NonNull
    public UUID id; @TypeConverters({UriConverter.class})
    @NonNull
    public Uri dirPath; @NonNull
    public String url; @NonNull
    public String fileName; public String description; public String mimeType; public long totalBytes; public int statusCode; public boolean unmeteredConnectionsOnly; public boolean retry; public boolean partialSupport; public String statusMsg; public long dateAdded; public int visibility; public boolean hasMetadata; public String userAgent; public int numFailed; public int retryAfter; public long lastModify; public String checksum; static final Parcelable.Creator<DownloadInfo> CREATOR; }
@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) { } }