FavoriteService { public void adjustFavoriteToFirst(long favoriteId) { Favorite favorite = favoriteRepository.findById(favoriteId).orElse(null); checkUserOperatePermission(favorite); String userId = favorite.getUserId(); Favorite firstFavorite = favoriteRepository.findFirstByUserIdOrderByPositionAscDataChangeCreatedTimeAsc(userId); long minPosition = firstFavorite.getPosition(); favorite.setPosition(minPosition - 1); favoriteRepository.save(favorite); } FavoriteService(
      final UserInfoHolder userInfoHolder,
      final FavoriteRepository favoriteRepository,
      final UserService userService); Favorite addFavorite(Favorite favorite); List<Favorite> search(String userId, String appId, Pageable page); void deleteFavorite(long favoriteId); void adjustFavoriteToFirst(long favoriteId); void batchDeleteByAppId(String appId, String operator); static final long POSITION_DEFAULT; }
@Test(expected = BadRequestException.class) @Sql(scripts = "/sql/favorites/favorites.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD) @Sql(scripts = "/sql/cleanup.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD) public void testAdjustFavoriteError() { long anotherPersonFavoriteId = 23; favoriteService.adjustFavoriteToFirst(anotherPersonFavoriteId); }