Skip to content

Commit

Permalink
fix upload list comparator to make it respect the comparator contract
Browse files Browse the repository at this point in the history
Signed-off-by: Daniele Fognini <dfogni@gmail.com>
  • Loading branch information
fogninid committed Jul 23, 2019
1 parent 881f7f1 commit f19f5f9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -736,16 +736,16 @@ private int compareUploadStatus(OCUpload upload1, OCUpload upload2) {
}

private int compareUploadingNow(OCUpload upload1, OCUpload upload2) {
return -Boolean.compare(upload1.isFixedUploadingNow(), upload2.isFixedUploadingNow());
}

private int compareUploadId(OCUpload upload1, OCUpload upload2) {
return Long.compare(upload1.getFixedUploadId(), upload2.getFixedUploadId());
return Boolean.compare(upload2.isFixedUploadingNow(), upload1.isFixedUploadingNow());
}

private int compareUpdateTime(OCUpload upload1, OCUpload upload2) {
return Long.compare(upload2.getFixedUploadEndTimeStamp(), upload1.getFixedUploadEndTimeStamp());
}

private int compareUploadId(OCUpload upload1, OCUpload upload2) {
return Long.compare(upload1.getFixedUploadId(), upload2.getFixedUploadId());
}
};

abstract class UploadGroup implements Refresh {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,30 @@ class UploadListAdapterTest {

@Test
fun `sort some uploads in the list`() {
val array = arrayOf(inProgress, inProgressNow, failedSameTimeOtherId, inProgressNow, null, failedLater, failed)
val array = arrayOf(
inProgress,
inProgressNow,
failedSameTimeOtherId,
inProgressNow,
null,
failedLater,
failed
)

array.sortWith(UploadListAdapter.uploadListComparator)
assertArrayEquals(arrayOf(null, inProgressNow, inProgressNow, inProgress, failedLater, failedSameTimeOtherId, failed), array)

assertArrayEquals(
arrayOf(
null,
inProgressNow,
inProgressNow,
inProgress,
failedLater,
failedSameTimeOtherId,
failed
),
array
)
}
}

Expand All @@ -120,7 +141,8 @@ class UploadListAdapterTest {
fun `comparator is reflective`() {
assertEquals(
-UploadListAdapter.uploadListComparator.compare(upload1, upload2),
UploadListAdapter.uploadListComparator.compare(upload2, upload1))
UploadListAdapter.uploadListComparator.compare(upload2, upload1)
)
}

@Test
Expand All @@ -135,7 +157,8 @@ class UploadListAdapterTest {
internal class UploadListComparatorGeneric3(
private val upload1: OCUpload,
private val upload2: OCUpload,
private val upload3: OCUpload) : Base() {
private val upload3: OCUpload
) : Base() {
companion object {
@JvmStatic
@Parameterized.Parameters(name = "{0}, {1}, {2}")
Expand Down

0 comments on commit f19f5f9

Please sign in to comment.