Skip to content

Commit

Permalink
Update DemoTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsaraira committed Oct 19, 2023
1 parent e3ffa16 commit 58beebd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/test/java/io/github/mrsaraira/constants/DemoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;

Expand Down Expand Up @@ -50,6 +49,7 @@ void enumContainersDemo() {
assertTrue(Constants.anyValue(2, DemoEnumConstantContainer.TWO));
assertTrue(Constants.anyValue(2, DemoEnumConstantContainer.ONE, DemoEnumConstantContainer.TWO));
assertFalse(Constants.anyValue(5, DemoEnumConstantContainer.THREE, DemoEnumConstantContainer.FOUR));

// match by value for relation containers
assertTrue(Constants.anyValue("Three", DemoEnumRelationConstantContainer.THREE, DemoEnumRelationConstantContainer.FOUR_FIVE));
assertFalse(Constants.anyValue("Seven", DemoEnumRelationConstantContainer.ONE, DemoEnumRelationConstantContainer.TWO));
Expand All @@ -65,10 +65,12 @@ void enumContainersDemo() {
assertEquals(1, twoRelationConstant.getRelations().length);
assertEquals(2, twoRelationConstant.getRelations()[0].getValue());

// Get enum by value
var optionalTwoEnum = Constants.getEnumByValue("Two", DemoEnumRelationConstantContainer.class);
assertTrue(optionalTwoEnum.isPresent());
assertEquals(DemoEnumRelationConstantContainer.TWO, optionalTwoEnum.get());

// get relation constant with relation value
var optionalFourFiveConstant = Constants.match(5, DemoEnumRelationConstantContainer.FOUR_FIVE);
assertTrue(optionalFourFiveConstant.isPresent());
assertEquals(DemoEnumRelationConstantContainer.FOUR_FIVE, optionalFourFiveConstant.get());
Expand Down Expand Up @@ -166,6 +168,7 @@ use the anonymous class anywhere beside this method, also you have container ins
assertTrue(Constants.anyRelationValue(1, DemoRelationContainerWithStaticFinalFields.ONE, DemoRelationContainerWithStaticFinalFields.TWO, DemoRelationContainerWithStaticFinalFields.THREE));
// Check any value by container constants references
var containerWithFields = Constants.getInstance(DemoContainerWithStaticFields.class);
assertNotNull(containerWithFields);
assertTrue(Constants.anyValue("One", DemoContainerWithStaticFields.ONE, DemoContainerWithStaticFields.TWO, DemoContainerWithStaticFields.THREE));
// Check any value by combining different constants from different containers as long they have same generic value type
assertTrue(Constants.anyValue("One", DemoContainerWithStaticFields.ONE, DemoRelationContainerWithStaticFinalFields.ONE.getKey()));
Expand Down

0 comments on commit 58beebd

Please sign in to comment.