Skip to content

Commit

Permalink
Server Unit Tests
Browse files Browse the repository at this point in the history
Removed Captor annotation as we no longer MockitoExtension
  • Loading branch information
Zargess committed Dec 1, 2024
1 parent 69227cb commit 2dfa43b
Showing 1 changed file with 31 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import com.fagi.model.GetFriendListRequest;
import com.fagi.model.User;
import com.fagi.model.messages.lists.FriendList;
import com.fagi.util.OutputAgentTestUtil;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mockito;

import java.util.ArrayList;
Expand All @@ -21,11 +20,8 @@
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

class GetFriendListRequestTests extends BaseInputHandlerTest {
@Captor private ArgumentCaptor<FriendList> friendListArgumentCaptor;
private final List<String> friendsUsernames = new ArrayList<>();

void beforeEach() {
Expand All @@ -47,23 +43,26 @@ void beforeEach() {
@Test
void gettingFriendList_NeverReturnsNull() {
inputHandler.handleInput(new GetFriendListRequest("sender"));
verify(

var capturedFriendList = OutputAgentTestUtil.captureResponse(
outputAgent,
times(1)
).addResponse(friendListArgumentCaptor.capture());
assertNotNull(friendListArgumentCaptor.getValue());
FriendList.class
);

assertNotNull(capturedFriendList);
}

@Test
void whenUserHasNoFriends_ThenFriendListIsEmpty() {
inputHandler.handleInput(new GetFriendListRequest("sender"));
verify(

var capturedFriendList = OutputAgentTestUtil.captureResponse(
outputAgent,
times(1)
).addResponse(friendListArgumentCaptor.capture());
FriendList friendList = friendListArgumentCaptor.getValue();
assumeFalse(isNull(friendList));
assertTrue(getFriendListData(friendList).isEmpty());
FriendList.class
);

assumeFalse(isNull(capturedFriendList));
assertTrue(getFriendListData(capturedFriendList).isEmpty());
}

@Test
Expand All @@ -83,16 +82,15 @@ void whenUserHasTwoFriends_ThenFriendListShouldHaveTwoFriends() {

inputHandler.handleInput(new GetFriendListRequest("sender"));

verify(
var capturedFriendList = OutputAgentTestUtil.captureResponse(
outputAgent,
times(1)
).addResponse(friendListArgumentCaptor.capture());
FriendList.class
);

FriendList friendList = friendListArgumentCaptor.getValue();
assumeFalse(isNull(friendList));
assumeFalse(isNull(capturedFriendList));
assertEquals(
2,
getFriendListData(friendList).size()
getFriendListData(capturedFriendList).size()
);
}

Expand All @@ -107,15 +105,14 @@ void whenFriendIsOnline_ThenFriendInFriendListShouldShowIt() {

inputHandler.handleInput(new GetFriendListRequest("sender"));

verify(
var capturedFriendList = OutputAgentTestUtil.captureResponse(
outputAgent,
times(1)
).addResponse(friendListArgumentCaptor.capture());
FriendList.class
);

FriendList friendList = friendListArgumentCaptor.getValue();
assumeFalse(isNull(friendList));
assumeTrue(getFriendListData(friendList).size() == 1);
assertTrue(getFriendListData(friendList)
assumeFalse(isNull(capturedFriendList));
assumeTrue(getFriendListData(capturedFriendList).size() == 1);
assertTrue(getFriendListData(capturedFriendList)
.getFirst()
.online());
}
Expand All @@ -131,15 +128,14 @@ void whenFriendIsNotOnline_ThenFriendInFriendListShouldShowIt() {

inputHandler.handleInput(new GetFriendListRequest("sender"));

verify(
var capturedFriendList = OutputAgentTestUtil.captureResponse(
outputAgent,
times(1)
).addResponse(friendListArgumentCaptor.capture());
FriendList.class
);

FriendList friendList = friendListArgumentCaptor.getValue();
assumeFalse(isNull(friendList));
assumeTrue(getFriendListData(friendList).size() == 1);
assertFalse(getFriendListData(friendList)
assumeFalse(isNull(capturedFriendList));
assumeTrue(getFriendListData(capturedFriendList).size() == 1);
assertFalse(getFriendListData(capturedFriendList)
.getFirst()
.online());
}
Expand Down

0 comments on commit 2dfa43b

Please sign in to comment.