FFFF Refactor registry and fix a bug introduced by page supplier PR by stianst · Pull Request #31322 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ public <T> T getDependency(Class<T> typeClass, InstanceWrapper dependent) {
}

public void beforeEach(Object testInstance) {
findRequestedInstances(testInstance);
matchDeployedInstancesWithRequestedInstances();
deployRequestedInstances();
injectFields(testInstance);
}

private void findRequestedInstances(Object testInstance) {
Class testClass = testInstance.getClass();
RequestedInstance requestedServerInstance = createRequestedInstance(testClass.getAnnotations(), null);
requestedInstances.add(requestedServerInstance);
Expand All @@ -101,7 +108,9 @@ public void beforeEach(Object testInstance) {
LOGGER.tracev("Requested suppliers: {0}",
requestedInstances.stream().map(r -> r.getSupplier().getClass().getSimpleName()).collect(Collectors.joining(", ")));
}
}

private void matchDeployedInstancesWithRequestedInstances() {
Iterator<RequestedInstance<?, ?>> itr = requestedInstances.iterator();
while (itr.hasNext()) {
RequestedInstance<?, ?> requestedInstance = itr.next();
Expand All @@ -124,8 +133,10 @@ public void beforeEach(Object testInstance) {
}
}
}
}

itr = requestedInstances.iterator();
private void deployRequestedInstances() {
Iterator<RequestedInstance<?, ?>> itr = requestedInstances.iterator();
while (itr.hasNext()) {
RequestedInstance requestedInstance = itr.next();

Expand All @@ -140,7 +151,9 @@ public void beforeEach(Object testInstance) {

itr.remove();
}
}

private void injectFields(Object testInstance) {
for (Field f : testInstance.getClass().getDeclaredFields()) {
InstanceWrapper<?, ?> instance = getDeployedInstance(f.getType(), f.getAnnotations());
try {
Expand Down Expand Up @@ -208,7 +221,17 @@ private void destroy(InstanceWrapper instanceWrapper) {
}

private InstanceWrapper getDeployedInstance(RequestedInstance requestedInstance) {
return deployedInstances.stream().filter(i -> i.getValue().equals(requestedInstance.getValueType())).findFirst().orElse(null);
Class requestedValueType = requestedInstance.getValueType();
for (InstanceWrapper<?, ?> i : deployedInstances) {
if (requestedValueType != null) {
if (requestedValueType.isAssignableFrom(i.getValue().getClass())) {
return i;
}
} else if (i.getSupplier().equals(requestedInstance.getSupplier())) {
return i;
}
}
return null;
}

private void loadSuppliers() {
Expand Down
0