mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 06:58:41 +00:00
fix: Fix context object (#2415)
* fix pr builder goals * update links * add context-object to build * add autogenerated content * fix checkstyle findings
This commit is contained in:
@@ -18,49 +18,52 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
*/
|
||||
public class ServiceContextTest {
|
||||
|
||||
private static final String SERVICE = "SERVICE";
|
||||
private static final String SERVICE = "SERVICE";
|
||||
|
||||
private LayerA layerA;
|
||||
private LayerA layerA;
|
||||
|
||||
@BeforeEach
|
||||
void initiateLayerA() {
|
||||
this.layerA = new LayerA();
|
||||
}
|
||||
@BeforeEach
|
||||
void initiateLayerA() {
|
||||
this.layerA = new LayerA();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSameContextPassedBetweenLayers() {
|
||||
ServiceContext context1 = layerA.getContext();
|
||||
var layerB = new LayerB(layerA);
|
||||
ServiceContext context2 = layerB.getContext();
|
||||
var layerC = new LayerC(layerB);
|
||||
ServiceContext context3 = layerC.getContext();
|
||||
@Test
|
||||
void testSameContextPassedBetweenLayers() {
|
||||
ServiceContext context1 = layerA.getContext();
|
||||
var layerB = new LayerB(layerA);
|
||||
ServiceContext context2 = layerB.getContext();
|
||||
var layerC = new LayerC(layerB);
|
||||
ServiceContext context3 = layerC.getContext();
|
||||
|
||||
assertSame(context1, context2);
|
||||
assertSame(context2, context3);
|
||||
assertSame(context3, context1);
|
||||
}
|
||||
assertSame(context1, context2);
|
||||
assertSame(context2, context3);
|
||||
assertSame(context3, context1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testScopedDataPassedBetweenLayers() {
|
||||
layerA.addAccountInfo(SERVICE);
|
||||
var layerB = new LayerB(layerA);
|
||||
var layerC = new LayerC(layerB);
|
||||
layerC.addSearchInfo(SERVICE);
|
||||
ServiceContext context = layerC.getContext();
|
||||
@Test
|
||||
void testScopedDataPassedBetweenLayers() {
|
||||
layerA.addAccountInfo(SERVICE);
|
||||
var layerB = new LayerB(layerA);
|
||||
var layerC = new LayerC(layerB);
|
||||
layerC.addSearchInfo(SERVICE);
|
||||
ServiceContext context = layerC.getContext();
|
||||
|
||||
assertEquals(SERVICE,context.getAccountService());
|
||||
assertNull(context.getSessionService());
|
||||
assertEquals(SERVICE,context.getSearchService());
|
||||
}
|
||||
assertEquals(SERVICE, context.getAccountService());
|
||||
assertNull(context.getSessionService());
|
||||
assertEquals(SERVICE, context.getSearchService());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
assertEquals(layerA.getContext().toString(),"ServiceContext(AccountService=null, SessionService=null, SearchService=null)");
|
||||
layerA.addAccountInfo(SERVICE);
|
||||
assertEquals(layerA.getContext().toString(), "ServiceContext(AccountService=SERVICE, SessionService=null, SearchService=null)");
|
||||
var layerB = new LayerB(layerA);
|
||||
layerB.addSessionInfo(SERVICE);
|
||||
var layerC = new LayerC(layerB);
|
||||
assertEquals(layerC.getContext().toString(), "ServiceContext(AccountService=SERVICE, SessionService=SERVICE, SearchService=null)");
|
||||
}
|
||||
@Test
|
||||
void testToString() {
|
||||
assertEquals(layerA.getContext().toString(),
|
||||
"ServiceContext(AccountService=null, SessionService=null, SearchService=null)");
|
||||
layerA.addAccountInfo(SERVICE);
|
||||
assertEquals(layerA.getContext().toString(),
|
||||
"ServiceContext(AccountService=SERVICE, SessionService=null, SearchService=null)");
|
||||
var layerB = new LayerB(layerA);
|
||||
layerB.addSessionInfo(SERVICE);
|
||||
var layerC = new LayerC(layerB);
|
||||
assertEquals(layerC.getContext().toString(),
|
||||
"ServiceContext(AccountService=SERVICE, SessionService=SERVICE, SearchService=null)");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user