Skip to content

Commit ed7a85e

Browse files
committed
fix: add test case for private getter (#175)
* fix: add test case for private getter * fix: polish test
1 parent 739bdca commit ed7a85e

File tree

4 files changed

+275
-244
lines changed

4 files changed

+275
-244
lines changed

graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/IntrospectionUtils.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.Iterator;
1414
import java.util.LinkedHashMap;
1515
import java.util.Map;
16+
import java.util.NoSuchElementException;
1617
import java.util.Objects;
1718
import java.util.Optional;
1819
import java.util.Spliterator;
@@ -48,12 +49,12 @@ public static EntityIntrospectionResult introspect(Class<?> entity) {
4849
* @param entity a Java entity class to introspect
4950
* @param propertyName the name of the property
5051
* @return true if property has Transient annotation or transient field modifier
51-
* @throws RuntimeException if property does not exists
52+
* @throws NoSuchElementException if property does not exists
5253
*/
5354
public static boolean isTransient(Class<?> entity, String propertyName) {
5455
return introspect(entity).getPropertyDescriptor(propertyName)
5556
.map(AttributePropertyDescriptor::isTransient)
56-
.orElseThrow(() -> new RuntimeException(new NoSuchFieldException(propertyName)));
57+
.orElseThrow(() -> new NoSuchElementException(propertyName));
5758
}
5859

5960
/**
@@ -62,9 +63,9 @@ public static boolean isTransient(Class<?> entity, String propertyName) {
6263
* @param entity a Java entity class to introspect
6364
* @param propertyName the name of the property
6465
* @return true if property is persitent
65-
* @throws RuntimeException if property does not exists
66+
* @throws NoSuchElementException if property does not exists
6667
*/
67-
public static boolean isPesistent(Class<?> entity, String propertyName) {
68+
public static boolean isPersistent(Class<?> entity, String propertyName) {
6869
return !isTransient(entity, propertyName);
6970
}
7071

@@ -74,12 +75,12 @@ public static boolean isPesistent(Class<?> entity, String propertyName) {
7475
* @param entity a Java entity class to introspect
7576
* @param propertyName the name of the property
7677
* @return true if property has GraphQLIgnore annotation
77-
* @throws RuntimeException if property does not exists
78+
* @throws NoSuchElementException if property does not exists
7879
*/
7980
public static boolean isIgnored(Class<?> entity, String propertyName) {
8081
return introspect(entity).getPropertyDescriptor(propertyName)
8182
.map(AttributePropertyDescriptor::isIgnored)
82-
.orElseThrow(() -> new RuntimeException(new NoSuchFieldException(propertyName)));
83+
.orElseThrow(() -> new NoSuchElementException(propertyName));
8384
}
8485

8586
/**
@@ -88,7 +89,7 @@ public static boolean isIgnored(Class<?> entity, String propertyName) {
8889
* @param entity a Java entity class to introspect
8990
* @param propertyName the name of the property
9091
* @return true if property has no GraphQLIgnore annotation
91-
* @throws RuntimeException if property does not exists
92+
* @throws NoSuchElementException if property does not exists
9293
*/
9394
public static boolean isNotIgnored(Class<?> entity, String propertyName) {
9495
return !isIgnored(entity, propertyName);

graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/CalculatedEntityTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public void testIgnoreFields() {
8484
" fieldMem" +
8585
" fieldFun" +
8686
" logic" +
87+
" age" +
8788
" customLogic" +
8889
" hideField" +
8990
" hideFieldFunction" +

0 commit comments

Comments
 (0)