-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
112 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,12 @@ | |
package com.github.benmanes.caffeine.cache; | ||
|
||
import static com.google.common.truth.Truth.assertAbout; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.jspecify.annotations.Nullable; | ||
|
||
import com.github.benmanes.caffeine.testing.CollectionSubject; | ||
import com.google.common.collect.Sets; | ||
import com.google.common.truth.FailureMetadata; | ||
|
@@ -29,10 +32,10 @@ | |
* @author [email protected] (Ben Manes) | ||
*/ | ||
final class LinkedDequeSubject extends CollectionSubject { | ||
private final LinkedDeque<Object> actual; | ||
private final @Nullable LinkedDeque<Object> actual; | ||
|
||
@SuppressWarnings("unchecked") | ||
private LinkedDequeSubject(FailureMetadata metadata, LinkedDeque<?> subject) { | ||
private LinkedDequeSubject(FailureMetadata metadata, @Nullable LinkedDeque<?> subject) { | ||
super(metadata, subject); | ||
this.actual = (LinkedDeque<Object>) subject; | ||
} | ||
|
@@ -46,6 +49,7 @@ public static LinkedDequeSubject assertThat(LinkedDeque<?> actual) { | |
} | ||
|
||
public void isValid() { | ||
requireNonNull(actual); | ||
if (actual.isEmpty()) { | ||
isExhaustivelyEmpty(); | ||
} | ||
|
@@ -65,6 +69,7 @@ private void checkIterator(Iterator<?> iterator) { | |
} | ||
|
||
private void checkElement(Object element) { | ||
requireNonNull(actual); | ||
var first = actual.peekFirst(); | ||
var last = actual.peekLast(); | ||
if (element == first) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.truth.Truth.assertAbout; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.Collection; | ||
import java.util.Deque; | ||
|
@@ -25,6 +26,8 @@ | |
import java.util.Queue; | ||
import java.util.Set; | ||
|
||
import org.jspecify.annotations.Nullable; | ||
|
||
import com.google.common.truth.FailureMetadata; | ||
import com.google.common.truth.IterableSubject; | ||
|
||
|
@@ -34,9 +37,9 @@ | |
* @author [email protected] (Ben Manes) | ||
*/ | ||
public class CollectionSubject extends IterableSubject { | ||
private final Collection<?> actual; | ||
private final @Nullable Collection<?> actual; | ||
|
||
public CollectionSubject(FailureMetadata metadata, Collection<?> subject) { | ||
public CollectionSubject(FailureMetadata metadata, @Nullable Collection<?> subject) { | ||
super(metadata, subject); | ||
this.actual = subject; | ||
} | ||
|
@@ -56,6 +59,7 @@ public final void hasSize(long expectedSize) { | |
|
||
/** Fails if the collection does not have less than the given size. */ | ||
public void hasSizeLessThan(long other) { | ||
requireNonNull(actual); | ||
checkArgument(other >= 0, "expectedSize (%s) must be >= 0", other); | ||
check("size()").that(actual.size()).isLessThan(Math.toIntExact(other)); | ||
} | ||
|
@@ -68,6 +72,7 @@ public void hasSizeLessThan(long other) { | |
public void isExhaustivelyEmpty() { | ||
checkIterable(); | ||
checkCollection(); | ||
requireNonNull(actual); | ||
if (actual instanceof Set<?>) { | ||
checkSet((Set<?>) actual); | ||
} | ||
|
@@ -83,11 +88,13 @@ public void isExhaustivelyEmpty() { | |
} | ||
|
||
private void checkIterable() { | ||
requireNonNull(actual); | ||
check("iterator().hasNext()").that(actual.iterator().hasNext()).isFalse(); | ||
} | ||
|
||
@SuppressWarnings("CollectionToArray") | ||
private void checkCollection() { | ||
requireNonNull(actual); | ||
check("size()").that(actual).hasSize(0); | ||
check("isEmpty()").that(actual).isEmpty(); | ||
check("toArray()").that(actual.toArray()).isEmpty(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.