Skip to content

Commit

Permalink
Feat: conflicts solved
Browse files Browse the repository at this point in the history
  • Loading branch information
kz44 committed Feb 1, 2024
1 parent 278e5c9 commit e0ad4a4
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
@RequestMapping("/api/v1/sports")
public class SportController {

private final SportService sportService;
private final SportService sportService;

/**
* This endpoint returns paginated list of SportDto.
*
* @param pageable contains tha page and size value
* @return paginated list of SportDTO
*/
@GetMapping("/all")
public List<SportDTO> getSports(final Pageable pageable) {
return sportService.getAllSports(pageable);
}
/**
* This endpoint returns paginated list of SportDto.
*
* @param pageable contains tha page and size value
* @return paginated list of SportDTO
*/
@GetMapping("/all")
public List<SportDTO> getSports(final Pageable pageable) {
return sportService.getAllSports(pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
@Component
public class SportMapper {

/**
* Converts a Sport entity to a SportDTO.
*
* @param entity The Sport entity to be converted.
* @return SportDTO containing information from the Sport entity.
*/
public SportDTO toDTO(Sport entity) {
return SportDTO.builder()
.name(entity.getName())
.build();
}
/**
* Converts a Sport entity to a SportDTO.
*
* @param entity The Sport entity to be converted.
* @return SportDTO containing information from the Sport entity.
*/
public SportDTO toDTO(Sport entity) {
return SportDTO.builder()
.name(entity.getName())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
@Repository
public interface SportRepository extends JpaRepository<Sport, Long> {

Optional<Sport> findSportByName(String name);
Optional<Sport> findSportByName(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import java.util.List;

public interface SportService {
List<SportDTO> getAllSports(final Pageable pageable);
List<SportDTO> getAllSports(final Pageable pageable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
@RequiredArgsConstructor
public class SportServiceImp implements SportService {

private final SportRepository sportRepository;
private final SportMapper sportMapper;
private final SportRepository sportRepository;
private final SportMapper sportMapper;


/**
* This method returns a paginated list of SportsDTO.
*
* @param pageable contains the page and size values for pagination.
* @return paginated list of SportDTO.
*/
public List<SportDTO> getAllSports(final Pageable pageable) {
return sportRepository.findAll(pageable).stream()
.map(sportMapper::toDTO)
.collect(Collectors.toList());
}
/**
* This method returns a paginated list of SportsDTO.
*
* @param pageable contains the page and size values for pagination.
* @return paginated list of SportDTO.
*/
public List<SportDTO> getAllSports(final Pageable pageable) {
return sportRepository.findAll(pageable)
.stream()
.map(sportMapper::toDTO)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,35 @@
@SpringBootTest
class SportServiceImpTest {

@Mock
private SportRepository sportRepository;
@Mock
private SportRepository sportRepository;

@InjectMocks
private SportServiceImp sportService;
@InjectMocks
private SportServiceImp sportService;

@Test
void getAllSportsShouldReturnAllSportsWhenRequired() {
// Arrange
Pageable pageable = Mockito.mock(Pageable.class);
@Test
void getAllSportsShouldReturnAllSportsWhenRequired() {
// Arrange
Pageable pageable = Mockito.mock(Pageable.class);

Sport sport1 = new Sport("Football");
Sport sport2 = new Sport("Basketball");
Sport sport1 = new Sport("Football");
Sport sport2 = new Sport("Basketball");

List<Sport> sports = Arrays.asList(sport1, sport2);
Page<Sport> sportsPage = new PageImpl<>(sports, pageable, sports.size());
List<Sport> sports = Arrays.asList(sport1, sport2);
Page<Sport> sportsPage = new PageImpl<>(sports, pageable, sports.size());

SportDTO sportDTO1 = new SportDTO("Football");
SportDTO sportDTO2 = new SportDTO("Basketball");
SportDTO sportDTO1 = new SportDTO("Football");
SportDTO sportDTO2 = new SportDTO("Basketball");

List<SportDTO> expectedSportDTOs = Arrays.asList(sportDTO1, sportDTO2);
List<SportDTO> expectedSportDTOs = Arrays.asList(sportDTO1, sportDTO2);

// Mocking repository
Mockito.when(sportRepository.findAll(Mockito.any(Pageable.class))).thenReturn(sportsPage);
// Mocking repository
Mockito.when(sportRepository.findAll(Mockito.any(Pageable.class))).thenReturn(sportsPage);

// Act
List<SportDTO> result = sportService.getAllSports(pageable);
// Act
List<SportDTO> result = sportService.getAllSports(pageable);

// Assert
assertEquals(expectedSportDTOs, result);
}
// Assert
assertEquals(expectedSportDTOs, result);
}
}

0 comments on commit e0ad4a4

Please sign in to comment.