Testing a method that transforms a dynamic list into another list?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I am trying to improve my test for a method that fetches all records from a DB and transforms them into API objects along with some business logic.
@Test
public void getAllUsers() throws Exception
final List<User> users = ImmutableList.of(
new User(), new User()
);
final List<UserResponse> expected = ImmutableList.of(
new UserResponse(), new UserResponse()
);
when(userDao.all()).thenReturn(users);
when(mapper.map(new User())).thenReturn(new UserResponse());
assertEquals(expected, this.userService.getAllUsers());
At the moment I have two lists filled will empty objects.
Is there a better way to initialise a list with dummy data, without having to explicitly build each object in the list with code?
Code under test
public List<UserResponse> getAllUsers() throws UserServiceException
try
return this.userDao.all()
.stream()
.map(mapper::map)
.collect(Collectors.toList());
catch (SQLException e)
throw new UserServiceException(e.getMessage());
Also are there any other checks I should be doing at this point?
Note: the mapper class is tested separately
java junit
add a comment |Â
up vote
0
down vote
favorite
I am trying to improve my test for a method that fetches all records from a DB and transforms them into API objects along with some business logic.
@Test
public void getAllUsers() throws Exception
final List<User> users = ImmutableList.of(
new User(), new User()
);
final List<UserResponse> expected = ImmutableList.of(
new UserResponse(), new UserResponse()
);
when(userDao.all()).thenReturn(users);
when(mapper.map(new User())).thenReturn(new UserResponse());
assertEquals(expected, this.userService.getAllUsers());
At the moment I have two lists filled will empty objects.
Is there a better way to initialise a list with dummy data, without having to explicitly build each object in the list with code?
Code under test
public List<UserResponse> getAllUsers() throws UserServiceException
try
return this.userDao.all()
.stream()
.map(mapper::map)
.collect(Collectors.toList());
catch (SQLException e)
throw new UserServiceException(e.getMessage());
Also are there any other checks I should be doing at this point?
Note: the mapper class is tested separately
java junit
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to improve my test for a method that fetches all records from a DB and transforms them into API objects along with some business logic.
@Test
public void getAllUsers() throws Exception
final List<User> users = ImmutableList.of(
new User(), new User()
);
final List<UserResponse> expected = ImmutableList.of(
new UserResponse(), new UserResponse()
);
when(userDao.all()).thenReturn(users);
when(mapper.map(new User())).thenReturn(new UserResponse());
assertEquals(expected, this.userService.getAllUsers());
At the moment I have two lists filled will empty objects.
Is there a better way to initialise a list with dummy data, without having to explicitly build each object in the list with code?
Code under test
public List<UserResponse> getAllUsers() throws UserServiceException
try
return this.userDao.all()
.stream()
.map(mapper::map)
.collect(Collectors.toList());
catch (SQLException e)
throw new UserServiceException(e.getMessage());
Also are there any other checks I should be doing at this point?
Note: the mapper class is tested separately
java junit
I am trying to improve my test for a method that fetches all records from a DB and transforms them into API objects along with some business logic.
@Test
public void getAllUsers() throws Exception
final List<User> users = ImmutableList.of(
new User(), new User()
);
final List<UserResponse> expected = ImmutableList.of(
new UserResponse(), new UserResponse()
);
when(userDao.all()).thenReturn(users);
when(mapper.map(new User())).thenReturn(new UserResponse());
assertEquals(expected, this.userService.getAllUsers());
At the moment I have two lists filled will empty objects.
Is there a better way to initialise a list with dummy data, without having to explicitly build each object in the list with code?
Code under test
public List<UserResponse> getAllUsers() throws UserServiceException
try
return this.userDao.all()
.stream()
.map(mapper::map)
.collect(Collectors.toList());
catch (SQLException e)
throw new UserServiceException(e.getMessage());
Also are there any other checks I should be doing at this point?
Note: the mapper class is tested separately
java junit
asked Jun 21 at 14:23
tomaytotomato
1486
1486
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f196982%2ftesting-a-method-that-transforms-a-dynamic-list-into-another-list%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password