Skip to content

Commit

Permalink
Add test for root on navigator
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Apr 25, 2023
1 parent d781a7f commit bbb28b8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public interface ElideEndpointBuilder<T extends ElideEntity> {
Class<T> getDtoClass();

ElideEndpointBuilder<T> addInclude(String include);

boolean isRoot();
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ public static <T extends ElideEntity> ElideNavigatorOnId<T> of(@NotNull UpdateDt
return new ElideNavigator<>((Class<T>) entity.getClass()).id(entity.getId());
}

/**
* Test if this navigator points to root endpoint
*/
@Override
public boolean isRoot() {
return parentNavigator.isEmpty();
}

/**
* Point to a certain id of entity type T
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

class ElideNavigatorTest {
@Test
Expand Down Expand Up @@ -106,4 +107,42 @@ void testGetFilter() {
assertThat(navigator.getFilter().get(), is(condition));
}

@Test
void testCannotNavigateAfterIncludes() {
assertThrows(IllegalStateException.class, () -> ElideNavigator.of(MapPoolAssignment.class)
.id("1")
.addInclude("mapVersion")
.navigateRelationship(MapVersion.class, "mapVersion"));
}

@Test
void testIsRootCollection() {
ElideNavigatorOnCollection<MapPoolAssignment> navigator = ElideNavigator.of(MapPoolAssignment.class).collection();
assertThat(navigator.isRoot(), is(true));
}

@Test
void testIsRootId() {
ElideNavigatorOnId<MapPoolAssignment> navigator = ElideNavigator.of(MapPoolAssignment.class).id("1");
assertThat(navigator.isRoot(), is(true));
}

@Test
void testIsNotRootCollection() {
ElideNavigatorOnCollection<MapVersion> navigator = ElideNavigator.of(MapPoolAssignment.class)
.id("1")
.navigateRelationship(MapVersion.class, "mapVersion")
.collection();
assertThat(navigator.isRoot(), is(false));
}

@Test
void testIsNotRootId() {
ElideNavigatorOnId<MapVersion> navigator = ElideNavigator.of(MapPoolAssignment.class)
.id("1")
.navigateRelationship(MapVersion.class, "mapVersion")
.id("1");
assertThat(navigator.isRoot(), is(false));
}

}

0 comments on commit bbb28b8

Please sign in to comment.