-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
072f169
commit c5a03ee
Showing
13 changed files
with
127 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...rastructure/src/main/java/com/paypal/infrastructure/mirakl/client/filter/ShopsFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.paypal.infrastructure.mirakl.client.filter; | ||
|
||
import com.mirakl.client.mmp.domain.shop.MiraklShops; | ||
|
||
public interface ShopsFilter { | ||
|
||
void filterShops(final MiraklShops shops); | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...e/src/main/java/com/paypal/infrastructure/mirakl/client/filter/TerminatedShopsFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.paypal.infrastructure.mirakl.client.filter; | ||
|
||
import com.mirakl.client.mmp.domain.shop.MiraklShop; | ||
import com.mirakl.client.mmp.domain.shop.MiraklShopState; | ||
import com.mirakl.client.mmp.domain.shop.MiraklShops; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
@Component | ||
public class TerminatedShopsFilter implements ShopsFilter { | ||
|
||
public void filterShops(final MiraklShops shops) { | ||
final List<MiraklShop> validShops = shops.getShops().stream().filter(this::isNotShopStatusTerminated) | ||
.collect(Collectors.toList()); | ||
|
||
shops.setShops(validShops); | ||
shops.setTotalCount((long) validShops.size()); | ||
} | ||
|
||
private boolean isNotShopStatusTerminated(final MiraklShop miraklShop) { | ||
return miraklShop.getState() != MiraklShopState.TERMINATED; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...c/test/java/com/paypal/infrastructure/mirakl/client/filter/TerminatedShopsFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.paypal.infrastructure.mirakl.client.filter; | ||
|
||
import com.mirakl.client.mmp.domain.shop.MiraklShop; | ||
import com.mirakl.client.mmp.domain.shop.MiraklShopState; | ||
import com.mirakl.client.mmp.domain.shop.MiraklShops; | ||
import com.paypal.infrastructure.mirakl.configuration.MiraklApiClientConfig; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.ArgumentMatchers.argThat; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class TerminatedShopsFilterTest { | ||
|
||
@InjectMocks | ||
private TerminatedShopsFilter testObj; | ||
|
||
@Mock | ||
private MiraklShops miraklShopsMock; | ||
|
||
@Mock | ||
private MiraklShop miraklShop1Mock, miraklShop2Mock, miraklShop3Mock; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
final MiraklApiClientConfig config = new MiraklApiClientConfig(); | ||
config.setOperatorApiKey("OPERATOR-KEY"); | ||
config.setEnvironment("environment"); | ||
} | ||
|
||
@Test | ||
void getShops_shouldFilterShopsHaveStateAsTerminated() { | ||
when(miraklShopsMock.getShops()).thenReturn(List.of(miraklShop1Mock, miraklShop2Mock, miraklShop3Mock)); | ||
when(miraklShop1Mock.getState()).thenReturn(MiraklShopState.TERMINATED); | ||
when(miraklShop2Mock.getState()).thenReturn(MiraklShopState.OPEN); | ||
when(miraklShop3Mock.getState()).thenReturn(MiraklShopState.SUSPENDED); | ||
|
||
testObj.filterShops(miraklShopsMock); | ||
|
||
verify(miraklShopsMock, times(1)).setShops(argThat(x -> x.size() == 2)); | ||
verify(miraklShopsMock, times(1)) | ||
.setShops(argThat(x -> x.containsAll(List.of(miraklShop2Mock, miraklShop3Mock)))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters