-
Notifications
You must be signed in to change notification settings - Fork 78
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
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...ava/nl/jqno/equalsverifier/internal/reflection/instantiation/CachedValueProviderTest.java
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package nl.jqno.equalsverifier.internal.reflection.instantiation; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Optional; | ||
import nl.jqno.equalsverifier.internal.reflection.Tuple; | ||
import nl.jqno.equalsverifier.internal.reflection.TypeTag; | ||
import nl.jqno.equalsverifier.internal.reflection.instantiation.ValueProvider.Attributes; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class CachedValueProviderTest { | ||
|
||
private static final TypeTag INT = new TypeTag(int.class); | ||
|
||
private CachedValueProvider sut = new CachedValueProvider(); | ||
|
||
@Test | ||
public void aRegisteredValueCanBeFound() { | ||
sut.put(INT, null, Tuple.of(3, 2, 3)); | ||
assertEquals(Tuple.of(3, 2, 3), sut.provide(INT, Attributes.unlabeled()).get()); | ||
} | ||
|
||
@Test | ||
public void aValueRegisteredWithALabelCanBeFoundUnderThatLabel() { | ||
sut.put(INT, "label", Tuple.of(3, 2, 3)); | ||
assertEquals(Tuple.of(3, 2, 3), sut.provide(INT, Attributes.labeled("label")).get()); | ||
} | ||
|
||
@Test | ||
public void aValueRegisteredWithALabelCanNotBeFoundWithoutThatLabel() { | ||
sut.put(INT, "label", Tuple.of(3, 2, 3)); | ||
assertEquals(Optional.empty(), sut.provide(INT, Attributes.unlabeled())); | ||
} | ||
|
||
@Test | ||
public void aQueryWithLabelFallsBackToRegisteredValueWithoutLabel() { | ||
sut.put(INT, null, Tuple.of(3, 2, 3)); | ||
assertEquals(Tuple.of(3, 2, 3), sut.provide(INT, Attributes.labeled("label")).get()); | ||
} | ||
|
||
@Test | ||
public void aQueryWithLabelPrefersRegisteredValueWithThatLabel() { | ||
sut.put(INT, null, Tuple.of(3, 2, 3)); | ||
sut.put(INT, "label", Tuple.of(4, 3, 4)); | ||
assertEquals(Tuple.of(4, 3, 4), sut.provide(INT, Attributes.labeled("label")).get()); | ||
} | ||
|
||
@Test | ||
public void anUnregisteredValueCanNotBeFound() { | ||
assertEquals(Optional.empty(), sut.provide(INT, Attributes.unlabeled())); | ||
} | ||
} |