3030import com .iluwatar .corruption .system .modern .ModernOrder ;
3131import com .iluwatar .corruption .system .modern .ModernShop ;
3232import com .iluwatar .corruption .system .modern .Shipment ;
33- import org .junit .Test ;
34- import org .junit .runner .RunWith ;
33+ import org .junit .jupiter .api .Test ;
3534import org .springframework .beans .factory .annotation .Autowired ;
3635import org .springframework .boot .test .context .SpringBootTest ;
37- import org .springframework .test .context .junit4 .SpringRunner ;
3836
3937import java .util .Optional ;
4038
4139import static org .junit .jupiter .api .Assertions .*;
4240
43- @ RunWith (SpringRunner .class )
41+ import org .junit .jupiter .api .extension .ExtendWith ;
42+ import org .springframework .test .context .junit .jupiter .SpringExtension ;
43+
44+ @ ExtendWith (SpringExtension .class )
4445@ SpringBootTest
4546public class AntiCorruptionLayerTest {
4647
@@ -50,19 +51,13 @@ public class AntiCorruptionLayerTest {
5051 @ Autowired
5152 private ModernShop modernShop ;
5253
53-
5454 /**
5555 * Test the anti-corruption layer.
5656 * Main intention is to demonstrate how the anti-corruption layer works.
57- * <p>
5857 * The 2 shops (modern and legacy) should operate independently and in the same time synchronize the data.
59- * To avoid corrupting the domain models of the 2 shops, we use an anti-corruption layer
60- * that transforms one model to another under the hood.
61- *
6258 */
6359 @ Test
6460 public void antiCorruptionLayerTest () throws ShopException {
65-
6661 // a new order comes to the legacy shop.
6762 LegacyOrder legacyOrder = new LegacyOrder ("1" , "addr1" , "item1" , 1 , 1 );
6863 // place the order in the legacy shop.
@@ -71,41 +66,32 @@ public void antiCorruptionLayerTest() throws ShopException {
7166 Optional <LegacyOrder > legacyOrderWithIdOne = legacyShop .findOrder ("1" );
7267 assertEquals (Optional .of (legacyOrder ), legacyOrderWithIdOne );
7368
74- // a new order (or maybe just the same order) appears in the modern shop.
69+ // a new order (or maybe just the same order) appears in the modern shop
7570 ModernOrder modernOrder = new ModernOrder ("1" , new Customer ("addr1" ), new Shipment ("item1" , 1 , 1 ), "" );
76-
7771 // the system places it, but it checks if there is an order with the same id in the legacy shop.
7872 modernShop .placeOrder (modernOrder );
7973
8074 Optional <ModernOrder > modernOrderWithIdOne = modernShop .findOrder ("1" );
8175 // there is no new order placed since there is already an order with the same id in the legacy shop.
8276 assertTrue (modernOrderWithIdOne .isEmpty ());
83-
8477 }
78+
8579 /**
86- * Test the anti-corruption layer.
87- * Main intention is to demonstrate how the anti-corruption layer works.
88- * <p>
89- * This test tests the anti-corruption layer from the rule the orders should be the same in the both systems.
90- *
80+ * Test the anti-corruption layer when a conflict occurs between systems.
81+ * This test ensures that an exception is thrown when conflicting orders are placed.
9182 */
92- @ Test ( expected = ShopException . class )
83+ @ Test
9384 public void antiCorruptionLayerWithExTest () throws ShopException {
94-
9585 // a new order comes to the legacy shop.
9686 LegacyOrder legacyOrder = new LegacyOrder ("1" , "addr1" , "item1" , 1 , 1 );
9787 // place the order in the legacy shop.
9888 legacyShop .placeOrder (legacyOrder );
9989 // the order is placed as usual since there is no other orders with the id in the both systems.
10090 Optional <LegacyOrder > legacyOrderWithIdOne = legacyShop .findOrder ("1" );
10191 assertEquals (Optional .of (legacyOrder ), legacyOrderWithIdOne );
102-
10392 // a new order but with the same id and different data appears in the modern shop
10493 ModernOrder modernOrder = new ModernOrder ("1" , new Customer ("addr1" ), new Shipment ("item1" , 10 , 1 ), "" );
105-
10694 // the system rejects the order since there are 2 orders with contradiction there.
107- modernShop .placeOrder (modernOrder );
108-
109-
95+ assertThrows (ShopException .class , () -> modernShop .placeOrder (modernOrder ));
11096 }
111- }
97+ }
0 commit comments