Search in sources :

Example 1 with Friendslist

use of com.management.entities.Friendslist in project Internet-Software-Architectures by zivko11.

the class FriendsListControllerTests method ReadAllFriendsLists_ReturnsOK.

@Test
public void ReadAllFriendsLists_ReturnsOK() {
    // Arrange
    Mockery mock = new Mockery();
    friendsListRepository = mock.mock(FriendsListRepository.class);
    final ArrayList<Friendslist> list = new ArrayList<Friendslist>();
    Friendslist list1 = new Friendslist();
    list1.setFriendsStatus('P');
    Friendslist list2 = new Friendslist();
    list2.setFriendsStatus('A');
    list.add(list1);
    list.add(list2);
    mock.checking(new Expectations() {

        {
            oneOf(friendsListRepository).findAll();
            will(returnValue(list));
        }
    });
    FriendsListManager manager = new FriendsListManager(friendsListRepository);
    FriendsListController controller = new FriendsListController(manager);
    // Act
    ResponseEntity<List<FriendslistDTO>> response = controller.getFriendslists();
    ArrayList<FriendslistDTO> listDTO = (ArrayList<FriendslistDTO>) response.getBody();
    // Assert
    Assert.assertNotNull(controller);
    Assert.assertEquals(response, new ResponseEntity<List<FriendslistDTO>>(listDTO, HttpStatus.OK));
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) FriendslistDTO(com.management.dto.FriendslistDTO) FriendsListRepository(com.management.repositories.FriendsListRepository) ArrayList(java.util.ArrayList) FriendsListManager(com.management.managers.FriendsListManager) ArrayList(java.util.ArrayList) List(java.util.List) Mockery(org.jmock.Mockery) Friendslist(com.management.entities.Friendslist) Test(org.junit.Test)

Example 2 with Friendslist

use of com.management.entities.Friendslist in project Internet-Software-Architectures by zivko11.

the class FriendsListManagerTest method ReadFriendsList_ReturnsUser.

@Test
public void ReadFriendsList_ReturnsUser() {
    // Arrange
    Mockery mock = new Mockery();
    friendsListRepository = mock.mock(FriendsListRepository.class);
    final Friendslist list = new Friendslist();
    list.setFriendsStatus('P');
    mock.checking(new Expectations() {

        {
            oneOf(friendsListRepository).findOne(1);
            will(returnValue(list));
        }
    });
    FriendsListManager manager = new FriendsListManager(friendsListRepository);
    // Act
    FriendslistDTO dto = manager.Read(1);
    // Assert
    Assert.assertNotNull(dto);
    Assert.assertEquals(dto.getFriendsStatus(), list.getFriendsStatus());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) FriendslistDTO(com.management.dto.FriendslistDTO) FriendsListRepository(com.management.repositories.FriendsListRepository) Mockery(org.jmock.Mockery) Friendslist(com.management.entities.Friendslist) Test(org.junit.Test)

Example 3 with Friendslist

use of com.management.entities.Friendslist in project Internet-Software-Architectures by zivko11.

the class FriendsListManagerTest method ReadAllFriendsLists_ReturnsAllFriendsLists.

@Test
public void ReadAllFriendsLists_ReturnsAllFriendsLists() {
    // Arrange
    Mockery mock = new Mockery();
    friendsListRepository = mock.mock(FriendsListRepository.class);
    final ArrayList<Friendslist> list = new ArrayList<Friendslist>();
    Friendslist list1 = new Friendslist();
    list1.setFriendsStatus('P');
    Friendslist list2 = new Friendslist();
    list2.setFriendsStatus('A');
    list.add(list1);
    list.add(list2);
    mock.checking(new Expectations() {

        {
            oneOf(friendsListRepository).findAll();
            will(returnValue(list));
        }
    });
    FriendsListManager manager = new FriendsListManager(friendsListRepository);
    // Act
    ArrayList<FriendslistDTO> listDTO = manager.ReadAll();
    // Assert
    Assert.assertNotNull(listDTO);
    Assert.assertEquals(listDTO.get(0).getFriendsStatus(), list.get(0).getFriendsStatus());
    Assert.assertEquals(listDTO.get(1).getFriendsStatus(), list.get(1).getFriendsStatus());
    mock.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) FriendslistDTO(com.management.dto.FriendslistDTO) FriendsListRepository(com.management.repositories.FriendsListRepository) ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) Friendslist(com.management.entities.Friendslist) Test(org.junit.Test)

Example 4 with Friendslist

use of com.management.entities.Friendslist in project Internet-Software-Architectures by zivko11.

the class FriendsListManagerTest method AddingNewFriendsList_ReturnsBoolean.

@Test
public void AddingNewFriendsList_ReturnsBoolean() {
    // Arrange
    friendsListRepository = new FriendsListRepositoryFake();
    FriendslistDTO dto = new FriendslistDTO();
    dto.setFriendsStatus('P');
    FriendsListManager manager = new FriendsListManager(friendsListRepository);
    // Act and assert
    Assert.assertNotNull(manager);
    Assert.assertTrue(manager.Create(dto));
    Friendslist list = friendsListRepository.findOne(0);
    Assert.assertEquals(dto.getFriendsStatus(), list.getFriendsStatus());
}
Also used : FriendslistDTO(com.management.dto.FriendslistDTO) FriendsListRepositoryFake(com.management.fake.FriendsListRepositoryFake) Friendslist(com.management.entities.Friendslist) Test(org.junit.Test)

Example 5 with Friendslist

use of com.management.entities.Friendslist in project Internet-Software-Architectures by zivko11.

the class FriendsListManager method Read.

public FriendslistDTO Read(int id) {
    ModelMapper mapper = new ModelMapper();
    FriendslistDTO dto;
    try {
        Friendslist list = friendsListRepository.findOne(id);
        dto = mapper.map(list, FriendslistDTO.class);
    } catch (Exception exc) {
        exc.printStackTrace();
        return null;
    }
    return dto;
}
Also used : FriendslistDTO(com.management.dto.FriendslistDTO) Friendslist(com.management.entities.Friendslist) ModelMapper(org.modelmapper.ModelMapper)

Aggregations

Friendslist (com.management.entities.Friendslist)9 FriendslistDTO (com.management.dto.FriendslistDTO)7 Test (org.junit.Test)5 FriendsListRepository (com.management.repositories.FriendsListRepository)4 Expectations (org.jmock.Expectations)4 Mockery (org.jmock.Mockery)4 ModelMapper (org.modelmapper.ModelMapper)4 ArrayList (java.util.ArrayList)3 FriendsListManager (com.management.managers.FriendsListManager)2 FriendsListRepositoryFake (com.management.fake.FriendsListRepositoryFake)1 List (java.util.List)1