Skip to content

Commit dbb6baf

Browse files
committed
test: add shared test fixtures — TestEndpoint and ScriptFixtures
1 parent c2219bf commit dbb6baf

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dev.objz.commandbridge.net;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
5+
import dev.objz.commandbridge.net.proto.Envelope;
6+
7+
public class TestEndpoint implements Endpoint {
8+
private boolean open;
9+
10+
public TestEndpoint() {
11+
this.open = true;
12+
}
13+
14+
public TestEndpoint(boolean open) {
15+
this.open = open;
16+
}
17+
18+
@Override
19+
public CompletableFuture<Void> send(Envelope env) {
20+
return CompletableFuture.completedFuture(null);
21+
}
22+
23+
@Override
24+
public boolean isOpen() {
25+
return open;
26+
}
27+
28+
@Override
29+
public String describe() {
30+
return "test-endpoint";
31+
}
32+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package dev.objz.commandbridge.scripting.validation;
2+
3+
import java.lang.reflect.RecordComponent;
4+
import java.util.Map;
5+
6+
import dev.objz.commandbridge.scripting.bind.RecordBinder;
7+
8+
public class ScriptFixtures {
9+
10+
public static RecordBinder.MutableRecordBuffer createBuffer(Class<?> recordClass,
11+
Map<String, Object> fieldValues) {
12+
RecordComponent[] components = recordClass.getRecordComponents();
13+
Object[] values = new Object[components.length];
14+
15+
for (int i = 0; i < components.length; i++) {
16+
String name = components[i].getName();
17+
if (fieldValues.containsKey(name)) {
18+
values[i] = fieldValues.get(name);
19+
} else {
20+
values[i] = null;
21+
}
22+
}
23+
24+
return new RecordBinder.MutableRecordBuffer(recordClass, recordClass.getSimpleName(),
25+
components, values);
26+
}
27+
}

0 commit comments

Comments
 (0)