Skip to content

Commit 858b63b

Browse files
authored
Update spring-boot-dependencies from 2.7.6 to 2.7.7 (#332)
* Update spring-boot-dependencies from 2.7.6 to 2.7.7 * fix: add spliterator support for ResultStreamWrapper * fix: cleanup comments * fix: use direct stream spliterator in ResultStreamWrapper * fix: add ResultStreamWrapperTest unit test class
1 parent 0f812a0 commit 858b63b

File tree

3 files changed

+78
-13
lines changed

3 files changed

+78
-13
lines changed

graphql-jpa-query-build/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>org.springframework.boot</groupId>
3838
<artifactId>spring-boot-dependencies</artifactId>
39-
<version>2.7.6</version>
39+
<version>2.7.7</version>
4040
<type>pom</type>
4141
<scope>import</scope>
4242
</dependency>

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,22 @@ public static <T> List<T> wrap(Stream<T> stream,
3232
int size) {
3333
return (List<T>) Proxy.newProxyInstance(ResultStreamWrapper.class.getClassLoader(),
3434
new Class[] { List.class },
35-
new ListProxyInvocationHandler<T>(stream.iterator(),
35+
new ListProxyInvocationHandler<T>(stream,
3636
size));
3737
}
3838

3939
@SuppressWarnings("unchecked")
40-
public static <T> List<T> wrap(Collection<T> stream,
40+
public static <T> List<T> wrap(Collection<T> collection,
4141
int size) {
42-
return (List<T>) Proxy.newProxyInstance(ResultStreamWrapper.class.getClassLoader(),
43-
new Class[] { List.class },
44-
new ListProxyInvocationHandler<T>(stream.iterator(),
45-
size));
42+
return wrap(collection.stream(),
43+
size);
4644
}
4745

4846
static class ListProxyInvocationHandler<T> implements InvocationHandler {
49-
private final Iterator<T> stream;
47+
private final Stream<T> stream;
5048
private final int size;
5149

52-
public ListProxyInvocationHandler(Iterator<T> stream,
50+
public ListProxyInvocationHandler(Stream<T> stream,
5351
int size) {
5452
this.stream = stream;
5553
this.size = size;
@@ -61,7 +59,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
6159
return size;
6260
}
6361
else if("iterator".equals(method.getName())) {
64-
return new ResultIteratorWrapper(stream,
62+
return new ResultIteratorWrapper(stream.iterator(),
6563
size);
6664
} else if ("equals".equals(method.getName())) {
6765
// Only consider equal when proxies are identical.
@@ -71,10 +69,12 @@ else if ("hashCode".equals(method.getName())) {
7169
// Use hashCode of service locator proxy.
7270
return System.identityHashCode(proxy);
7371
}
74-
72+
else if ("spliterator".equals(method.getName())) {
73+
return stream.spliterator();
74+
}
7575
throw new UnsupportedOperationException(method + " is not supported");
7676
}
77-
77+
7878
class ResultIteratorWrapper implements Iterator<T> {
7979

8080
final Iterator<T> delegate;
@@ -103,6 +103,6 @@ public T next() {
103103
current++;
104104
}
105105
}
106-
}
106+
}
107107
}
108108
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.introproventures.graphql.jpa.query.schema.impl;
2+
3+
import java.util.Collections;
4+
import java.util.List;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
import static org.assertj.core.api.Assertions.catchException;
9+
10+
class ResultStreamWrapperTest {
11+
12+
@Test
13+
void wrap() {
14+
List result = ResultStreamWrapper.wrap(Collections.emptyList(), 0);
15+
16+
assertThat(result).hasSize(0);
17+
assertThat(result.equals(result)).isTrue();
18+
assertThat(result.hashCode()).isEqualTo(System.identityHashCode(result));
19+
}
20+
21+
@Test
22+
void _hashCode() {
23+
List result = ResultStreamWrapper.wrap(Collections.emptyList(), 0);
24+
25+
assertThat(result.hashCode()).isEqualTo(System.identityHashCode(result));
26+
}
27+
28+
@Test
29+
void equals() {
30+
List result = ResultStreamWrapper.wrap(Collections.emptyList(), 0);
31+
32+
assertThat(result.equals(result)).isTrue();
33+
}
34+
35+
36+
@Test
37+
void hasSize() {
38+
List result = ResultStreamWrapper.wrap(Collections.emptyList(), 0);
39+
40+
assertThat(result).hasSize(0);
41+
}
42+
43+
@Test
44+
void iterator() {
45+
List result = ResultStreamWrapper.wrap(Collections.emptyList(), 0);
46+
47+
assertThat(result.iterator()).isNotNull();
48+
}
49+
50+
@Test
51+
void spliterator() {
52+
List result = ResultStreamWrapper.wrap(Collections.emptyList(), 0);
53+
54+
assertThat(result.spliterator()).isNotNull();
55+
}
56+
57+
@Test
58+
void methodNotSupported() {
59+
List result = ResultStreamWrapper.wrap(Collections.emptyList(), 0);
60+
61+
Exception error = catchException(() -> result.get(0));
62+
63+
assertThat(error).isInstanceOf(UnsupportedOperationException.class);
64+
}
65+
}

0 commit comments

Comments
 (0)