feat(renderer): Add getOrAcquire method and enhance get method in RendererWorkingSet implementation
This commit is contained in:
@@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -315,7 +316,50 @@ public class RendererWorkingSetImplTest {
|
||||
assertTrue(filteredLive.containsAll(List.of(boA1, boA2)));
|
||||
assertFalse(filteredLive.contains(boB1));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void getWithTypeReturnsTypedInstanceAndNullForUnknown() {
|
||||
final var boA = new TestBoA();
|
||||
boA.setId("bo1");
|
||||
this.workingSet.put(this.moduleA.getId(), boA);
|
||||
|
||||
final var retrieved = this.workingSet.get(this.moduleA.getId(), "bo1", TestBoA.class);
|
||||
assertSame(boA, retrieved);
|
||||
|
||||
final var notFound = this.workingSet.get(this.moduleA.getId(), "nonexistent", TestBoA.class);
|
||||
assertTrue(notFound == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getWithTypeThrowsClassCastForWrongType() {
|
||||
final var boA = new TestBoA();
|
||||
boA.setId("bo1");
|
||||
this.workingSet.put(this.moduleA.getId(), boA);
|
||||
|
||||
assertThrows(ClassCastException.class, () -> this.workingSet.get(this.moduleA.getId(), "bo1", TestBoB.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void getOrAcquireReturnsUncommittedWhenPresent() {
|
||||
final var boA = new TestBoA();
|
||||
boA.setId("bo1");
|
||||
this.workingSet.put(this.moduleA.getId(), boA);
|
||||
|
||||
final var retrieved = this.workingSet.getOrAcquire(this.moduleA.getId(), "bo1", TestBoA.class);
|
||||
assertSame(boA, retrieved);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getOrAcquireAcquiresFromPoolWhenMissing() {
|
||||
final var pooledBo = new TestBoA();
|
||||
pooledBo.setId("pooled");
|
||||
when(this.renderingBoPool.acquire("pooled", TestBoA.class)).thenReturn(pooledBo);
|
||||
|
||||
final var retrieved = this.workingSet.getOrAcquire(this.moduleA.getId(), "pooled", TestBoA.class);
|
||||
assertSame(pooledBo, retrieved);
|
||||
verify(this.renderingBoPool, times(1)).acquire("pooled", TestBoA.class);
|
||||
}
|
||||
|
||||
private static abstract class TestBoBase implements RenderingBo {
|
||||
|
||||
private final AtomicInteger closeStaticCalls = new AtomicInteger();
|
||||
|
||||
Reference in New Issue
Block a user