-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…header safe guard within `ConflictException` (#208)
- Loading branch information
1 parent
ed3c97e
commit dccbe54
Showing
3 changed files
with
83 additions
and
12 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
60 changes: 60 additions & 0 deletions
60
events_mgmt/src/test/java/com/adobe/aio/event/management/feign/ConflictExceptionTest.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,60 @@ | ||
package com.adobe.aio.event.management.feign; | ||
|
||
import static com.adobe.aio.event.management.feign.ConflictException.X_CONFLICTING_ID; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
import feign.FeignException; | ||
import feign.Request; | ||
import feign.Response; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class ConflictExceptionTest { | ||
|
||
@Mock | ||
private Response response ; | ||
|
||
@Mock | ||
private Request request; | ||
|
||
@Mock | ||
private FeignException feignException; | ||
|
||
@BeforeEach | ||
void beforeeach() { | ||
when(response.request()).thenReturn(request); | ||
} | ||
|
||
@Test | ||
void withNoConflictIdHeader() { | ||
when(response.headers()).thenReturn(Collections.emptyMap()); | ||
assertEquals(null, new ConflictException(response, feignException).getConflictingId()); | ||
} | ||
|
||
@Test | ||
void withEmptyConflictIdHeader() { | ||
Map<String, Collection<String>> headers = new HashMap<>(); | ||
headers.put(X_CONFLICTING_ID, Collections.emptyList()); | ||
when(response.headers()).thenReturn(headers); | ||
assertEquals(null, new ConflictException(response, feignException).getConflictingId()); | ||
} | ||
|
||
@Test | ||
void withConflictIdHeader() { | ||
String conflictingId = "someId"; | ||
Map<String, Collection<String>> headers = new HashMap<>(); | ||
headers.put(X_CONFLICTING_ID, Collections.singletonList(conflictingId)); | ||
when(response.headers()).thenReturn(headers); | ||
assertEquals(conflictingId, new ConflictException(response, feignException).getConflictingId()); | ||
} | ||
|
||
} |