Skip to content

Commit

Permalink
Adds tests for CachedValueProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
jqno committed Nov 27, 2024
1 parent 142d44c commit d6171be
Showing 1 changed file with 52 additions and 0 deletions.
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()));
}
}

0 comments on commit d6171be

Please sign in to comment.