Skip to content

Commit

Permalink
cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
TihomirovPavel committed Sep 7, 2018
1 parent 7e2ca81 commit f37dd34
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/main/webapp/app/js/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ function generateMetrics(goals) {
open++;
}
}
var obj = "<table>" +
var statisticsTable = "<table>" +
"<tr><td><h4>Statistics</h4></td></tr>" +
"<tr><td>" + "Goals Total: " + goals.length + "</td></tr>" +
"<tr><td>" + "Goals Achieved: " + completed + "</td></tr>" +
"<tr><td>" + "Goals Overdue: " + overdue + "</td></tr>" +
"<tr><td>" + "Goals Open: " + open + "</td></tr>" +
"</table>";
document.getElementById("metrics").innerHTML = obj;
document.getElementById("metrics").innerHTML = statisticsTable;
}
54 changes: 27 additions & 27 deletions src/test/java/lv/ctco/javaschool/goal/boundary/GoalApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void init() {

@Test
@DisplayName("Test getUserById(): returns user if User exists")
void testGetUserByIdReturnsUserDtoIfUserExists() {
void test_GetUserById_ReturnsUserDto_IfUserExists() {
goalList1.add(goal);
UserDto userDto = DtoConverter.convertToUserDto(user1, goalList1);
when(userStore.getUserById(1L))
Expand All @@ -153,15 +153,15 @@ void testGetUserByIdReturnsUserDtoIfUserExists() {

@Test
@DisplayName("Test getUserById(): throws InvalidUserException if user does not exists(wrong id)")
void testGetUserByIdThrowsError() {
void test_GetUserById_ThrowsError() {
when(userStore.getUserById(1L))
.thenReturn(Optional.empty());
assertThrows(InvalidUserException.class, () -> goalApi.getUserById(1L));
}

@Test
@DisplayName("Test findGoalsForCurrentUser(): Current user has No goals returns empty list of dto's")
void testFindGoalsForCurrentUser() {
void test_FindGoalsForCurrentUser() {
when(userStore.getCurrentUser())
.thenReturn(user1);
when(goalStore.getGoalsByUser(user1))
Expand All @@ -171,7 +171,7 @@ void testFindGoalsForCurrentUser() {

@Test
@DisplayName("Test findGoalsForCurrentUser(): Current user has goals returns list of dto's")
void testFindGoalsForCurrentUserToReturnListOfDto() {
void test_FindGoalsForCurrentUser_ToReturnListOfDto() {
goalList1.add(goal);
when(userStore.getCurrentUser())
.thenReturn(user1);
Expand All @@ -184,7 +184,7 @@ void testFindGoalsForCurrentUserToReturnListOfDto() {

@Test
@DisplayName("Test getGoalById(): returns dto of goal by id")
void testGetGoalById() {
void test_GetGoalById() {
when(goalStore.getGoalById(1L))
.thenReturn(java.util.Optional.ofNullable(goal));
assertThat(goalApi.findGoalDtoByGoalId(1L).getId(), is(1L));
Expand All @@ -194,15 +194,15 @@ void testGetGoalById() {

@Test
@DisplayName("Test getGoalById(): throws InvalidGoalException")
void testGetGoalByIdException() {
void test_GetGoalById_Exception() {
when(goalStore.getGoalById(1L))
.thenReturn(java.util.Optional.empty());
assertThrows(InvalidGoalException.class, () -> goalApi.findGoalDtoByGoalId(1L));
}

@Test
@DisplayName("Test saveGoal(): check if persists new Goal")
void testSaveGoal() {
void test_SaveGoal() {
goalFormDto.setDeadline(LocalDate.of(9018, 10, 25));
goalFormDto.setGoalMessage("hi");
goalFormDto.setTags("qwjye|iwefyg|ksdgf");
Expand All @@ -218,15 +218,15 @@ void testSaveGoal() {

@Test
@DisplayName("Test saveGoal(): check if throws exception if empty fields of dto object")
void testSaveGoalException() {
void test_SaveGoal_Exception() {
when(userStore.getCurrentUser())
.thenReturn(user1);
assertThrows(InvalidGoalException.class, () -> goalApi.saveGoal(new GoalFormDto()));
}

@Test
@DisplayName("Test saveGoal(): check if throws exception if empty message inserted")
void testSaveGoalEmptyMessage() {
void test_SaveGoal_EmptyMessage() {
GoalFormDto testGoalFormDto = new GoalFormDto();
when(userStore.getCurrentUser())
.thenReturn(user1);
Expand All @@ -241,7 +241,7 @@ void testSaveGoalEmptyMessage() {

@Test
@DisplayName("Test saveGoal(): check if throws exception if there is invalid deadline date of dto object")
void testSaveGoalInvalidDeadline() {
void test_SaveGoal_InvalidDeadline() {
goalFormDto.setDeadline(LocalDate.of(1,1,1));
goalFormDto.setGoalMessage("hi");
goalFormDto.setTags("qwjye|iwefyg|ksdgf");
Expand All @@ -253,7 +253,7 @@ void testSaveGoalInvalidDeadline() {

@Test
@DisplayName("Test findCommentsForGoalById(): returns Comments dto of goal by id")
void testFindCommentsForGoalById() {
void test_FindCommentsForGoalById() {
comments.add(comment1);
when(goalStore.getGoalById(1L))
.thenReturn(java.util.Optional.ofNullable(goal));
Expand All @@ -266,7 +266,7 @@ void testFindCommentsForGoalById() {

@Test
@DisplayName("Test findCommentsForGoalById(): returns empty Comments dto of goal")
void testFindCommentsForGoalByIdEmptyCommentsDto() {
void test_FindCommentsForGoalById_EmptyCommentsDto() {
when(goalStore.getGoalById(1L))
.thenReturn(java.util.Optional.ofNullable(goal));
when(goalStore.getCommentsForGoal(goal))
Expand All @@ -277,7 +277,7 @@ void testFindCommentsForGoalByIdEmptyCommentsDto() {

@Test
@DisplayName("Test saveCommentsForGoalById(): verify if persists Comments")
void testSaveCommentsForGoalById() {
void test_SaveCommentsForGoalById() {
when(userStore.getCurrentUser())
.thenReturn(user1);
when(goalStore.getGoalById(1L))
Expand All @@ -288,15 +288,15 @@ void testSaveCommentsForGoalById() {

@Test
@DisplayName("Test saveCommentsForGoalById(): verify if throws exception if optional<goal> isEmpty")
void testSaveCommentsForGoalByIdException() {
void test_SaveCommentsForGoalById_Exception() {
when(goalStore.getGoalById(1L))
.thenReturn(Optional.empty());
assertThrows(InvalidGoalException.class, () -> goalApi.saveCommentsForGoalById(1L, msg));
}

@Test
@DisplayName("Test isCurrentUsersGoal(Long goalId): verify if goal is for current user is returned true")
void testIsCurrentUsersGoalForCurrentUser() {
void test_IsCurrentUsersGoal_ForCurrentUser() {
when(userStore.getCurrentUser())
.thenReturn(user1);
when(goalStore.getUnachievedUserGoalById(user1, 1L))
Expand All @@ -306,7 +306,7 @@ void testIsCurrentUsersGoalForCurrentUser() {

@Test
@DisplayName("Test isCurrentUsersGoal(Long goalId): verify if goal is for other user not current, then returned false")
void testIsCurrentUsersGoalForDifferentUser() {
void test_IsCurrentUsersGoal_ForDifferentUser() {
when(userStore.getCurrentUser())
.thenReturn(user2);
when(goalStore.getUnachievedUserGoalById(user2, 1L))
Expand All @@ -329,7 +329,7 @@ void testEditGoalForGoalOwner() {

@Test
@DisplayName("Test editGoal(Long goalId, GoalFormDto newGoalDto): verify that goal is not edited, if user did not create goal")
void testEditGoalForDifferentUser() {
void test_EditGoal_ForDifferentUser() {
String messageBeforeEdit = goal.getGoalMessage();
LocalDate deadlineDateBeforeEdit = goal.getDeadlineDate();
when(userStore.getCurrentUser())
Expand All @@ -344,7 +344,7 @@ void testEditGoalForDifferentUser() {

@Test
@DisplayName("Test editGoal(Long goalId, GoalFormDto newGoalDto): verify that goal is not edited, if goal is achieved")
void testEditGoalForAchievedGoal() {
void test_EditGoal_ForAchievedGoal() {
goal.setStatus(GoalStatus.ACHIEVED);
String messageBeforeEdit = goal.getGoalMessage();
LocalDate deadlineDateBeforeEdit = goal.getDeadlineDate();
Expand All @@ -360,7 +360,7 @@ void testEditGoalForAchievedGoal() {

@Test
@DisplayName("Test editGoal(Long goalId, GoalFormDto newGoalDto): verify that goal status is changed, if overdue goal deadline date is edited")
void testEditGoalForOverdueGoal() {
void test_EditGoal_ForOverdueGoal() {
goal.setStatus(GoalStatus.OVERDUE);
when(userStore.getCurrentUser())
.thenReturn(user1);
Expand All @@ -374,7 +374,7 @@ void testEditGoalForOverdueGoal() {

@Test
@DisplayName("Test editGoal(Long goalId, GoalFormDto newGoalDto): verify that goal is edited, if users new goal is empty")
void testEditGoalWithoutInput() {
void test_EditGoal_WithoutInput() {

when(userStore.getCurrentUser())
.thenReturn(user1);
Expand All @@ -383,15 +383,15 @@ void testEditGoalWithoutInput() {

@Test
@DisplayName("Test editGoal(Long goalId, GoalFormDto newGoalDto): verify that goal is edited, if user input invalid deadline date")
void testEditGoalInvalidDeadline() {
void test_EditGoal_InvalidDeadline() {
goalFormDto.setGoalMessage("123");
goalFormDto.setDeadline(LocalDate.of(1, 1, 1));
assertThrows(ValidationException.class, () -> goalApi.editGoal(1L, goalFormDto));
}

@Test
@DisplayName("Test findAllTags(): verify if throws exception if optional<goal> isEmpty")
void testFindAllTags() {
void test_FindAllTags() {
when(goalStore.getAllTags()).thenReturn(tagList);
List<TagDto> dtoList = goalApi.findAllTags();
assertThat(dtoList.size(), is(tagList.size()));
Expand All @@ -403,7 +403,7 @@ void testFindAllTags() {

@Test
@DisplayName("Test getGoalsByTag(JsonObject searchDto): returns list of GoalDto by Tag")
void testGetGoalsByTag() {
void test_GetGoalsByTag() {
List<Tag> tags = new ArrayList<>();
Tag tag1 = new Tag("test1");
Tag tag2 = new Tag("test2");
Expand All @@ -428,7 +428,7 @@ void testGetGoalsByTag() {

@Test
@DisplayName("Test getUsersByUsername(JsonObject searchDto): returns list of UserSearchDto and calling userStore.getUsersByUsername() method")
void testGetUsersByUsername() {
void test_GetUsersByUsername() {
List<User> users = new ArrayList<>();
Collections.addAll(users, user1, user2);
when(userStore.getUsersByUsername(anyString())).thenReturn(users);
Expand All @@ -455,7 +455,7 @@ private GoalFormDto setupGoalFormDto() {

@Test
@DisplayName("test setStatusAchieved: changes status")
void testSetStatusAchieved() {
void test_SetStatusAchieved() {
Long id = goal.getId();
goal.setStatus(GoalStatus.OVERDUE);
when(userStore.getCurrentUser())
Expand All @@ -468,7 +468,7 @@ void testSetStatusAchieved() {

@Test
@DisplayName("test setStatusAchieved: throws ValidationException wrong user")
void testSetStatusAchievedThrowsExceptionIfWrongUser() {
void test_SetStatusAchieved_ThrowsException_IfWrongUser() {
Long id = goal.getId();
goal.setStatus(GoalStatus.OVERDUE);
when(userStore.getCurrentUser())
Expand All @@ -480,7 +480,7 @@ void testSetStatusAchievedThrowsExceptionIfWrongUser() {

@Test
@DisplayName("test setStatusAchieved: throws ValidationException no goal")
void testSetStatusAchievedThrowsExceptionIfNoGoal() {
void test_SetStatusAchieved_ThrowsException_IfNoGoal() {
Long id = goal.getId();
goal.setStatus(GoalStatus.OPEN);
when(userStore.getCurrentUser())
Expand Down

0 comments on commit f37dd34

Please sign in to comment.