FarmerController.java

1
package edu.ucsb.cs156.happiercows.controllers;
2
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
6
import org.springframework.beans.factory.annotation.Autowired;
7
8
import org.springframework.security.access.prepost.PreAuthorize;
9
import org.springframework.web.bind.annotation.GetMapping;
10
import org.springframework.web.bind.annotation.RequestMapping;
11
import org.springframework.web.bind.annotation.RequestParam;
12
import org.springframework.web.bind.annotation.RestController;
13
14
import edu.ucsb.cs156.happiercows.repositories.FarmerRepository;
15
import edu.ucsb.cs156.happiercows.repositories.GameRepository;
16
import edu.ucsb.cs156.happiercows.repositories.HerdRepository;
17
import edu.ucsb.cs156.happiercows.entities.User;
18
import edu.ucsb.cs156.happiercows.entities.Farmer;
19
import edu.ucsb.cs156.happiercows.entities.FarmerActivity;
20
import edu.ucsb.cs156.happiercows.entities.Game;
21
import edu.ucsb.cs156.happiercows.entities.Herd;
22
import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException;
23
import edu.ucsb.cs156.happiercows.errors.InvalidNumberOfCowsException;
24
import edu.ucsb.cs156.happiercows.errors.NoCowsException;
25
import edu.ucsb.cs156.happiercows.errors.NotEnoughMoneyException;
26
import edu.ucsb.cs156.happiercows.errors.GameHiddenException;
27
import edu.ucsb.cs156.happiercows.errors.NotEnrolledInCourseAssociatedWithGameException;
28
import edu.ucsb.cs156.happiercows.models.FarmerWithStudentStatus;
29
import edu.ucsb.cs156.happiercows.services.CourseAccessService;
30
import edu.ucsb.cs156.happiercows.services.FarmerActivityService;
31
32
import java.util.ArrayList;
33
import java.util.HashMap;
34
import java.util.Map;
35
import java.util.List;
36
37
import io.swagger.v3.oas.annotations.tags.Tag;
38
import io.swagger.v3.oas.annotations.Operation;
39
import io.swagger.v3.oas.annotations.Parameter;
40
41
import org.springframework.http.ResponseEntity;
42
import org.springframework.web.bind.annotation.PutMapping;
43
import org.springframework.web.bind.annotation.RequestBody;
44
import org.springframework.transaction.annotation.Transactional;
45
46
@Tag(name = "User Game")
47
@RequestMapping("/api/farmer")
48
@RestController
49
public class FarmerController extends ApiController {
50
51
  @Autowired
52
  private FarmerRepository farmerRepository;
53
54
  @Autowired
55
  private GameRepository gameRepository;
56
57
  @Autowired
58
  private HerdRepository herdRepository;
59
60
  @Autowired
61
  ObjectMapper mapper;
62
63
  @Autowired
64
  private CourseAccessService courseAccessService;
65
66
  @Autowired
67
  private FarmerActivityService farmerActivityService;
68
69
  @Operation(summary = "Get a specific user game (admin only)")
70
  @PreAuthorize("hasRole('ROLE_ADMIN')")
71
  @GetMapping("")
72
  public Farmer getFarmerById(
73
      @Parameter(name="userId") @RequestParam Long userId,
74
      @Parameter(name="gameId") @RequestParam Long gameId) throws JsonProcessingException {
75
76
    Farmer farmer = farmerRepository.findByGameIdAndUserId(gameId, userId)
77
        .orElseThrow(
78 1 1. lambda$getFarmerById$0 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$getFarmerById$0 → KILLED
            () -> new EntityNotFoundException(Farmer.class, "gameId", gameId, "userId", userId));
79 1 1. getFarmerById : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::getFarmerById → KILLED
    return farmer;
80
  }
81
82
  @Operation(summary = "Get a user game for current user")
83
  @PreAuthorize("hasRole('ROLE_USER')")
84
  @GetMapping("/forcurrentuser")
85
  public Farmer getFarmerById(
86
      @Parameter(name="gameId") @RequestParam Long gameId) throws JsonProcessingException {
87
88
    User u = getCurrentUser().getUser();
89
    Long userId = u.getId();
90
    Game game = gameRepository.findById(gameId)
91 1 1. lambda$getFarmerById$1 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$getFarmerById$1 → KILLED
        .orElseThrow(() -> new EntityNotFoundException("Game", gameId));
92 1 1. getFarmerById : removed call to edu/ucsb/cs156/happiercows/controllers/FarmerController::ensureUserCanAccessCourseLinkedGame → KILLED
    ensureUserCanAccessCourseLinkedGame(u, game);
93
    Farmer farmer = farmerRepository.findByGameIdAndUserId(gameId, userId)
94
        .orElseThrow(
95 1 1. lambda$getFarmerById$2 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$getFarmerById$2 → KILLED
            () -> new EntityNotFoundException(Farmer.class, "gameId", gameId, "userId", userId));
96 1 1. getFarmerById : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::getFarmerById → KILLED
    return farmer;
97
  }
98
99
  @Operation(summary = "Buy a herd of numCows cows (starting at 100 health), totalWealth updated")
100
  @PreAuthorize("hasRole('ROLE_USER')")
101
  @PutMapping("/buy")
102
  public ResponseEntity<String> putFarmerByIdBuy(
103
          @Parameter(name="gameId") @RequestParam Long gameId,
104
          @Parameter(name="numCows") @RequestParam int numCows) throws NotEnoughMoneyException, InvalidNumberOfCowsException, JsonProcessingException{
105
106 2 1. putFarmerByIdBuy : changed conditional boundary → KILLED
2. putFarmerByIdBuy : negated conditional → KILLED
        if (numCows < 1) {
107
          throw new InvalidNumberOfCowsException("You must buy at least 1 cow!");
108
        }
109
110
        User u = getCurrentUser().getUser();
111
        Long userId = u.getId();
112
113
        Game game = gameRepository.findById(gameId).orElseThrow( 
114 1 1. lambda$putFarmerByIdBuy$0 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$putFarmerByIdBuy$0 → KILLED
          ()->new EntityNotFoundException("Game", gameId));
115
116 1 1. putFarmerByIdBuy : removed call to edu/ucsb/cs156/happiercows/controllers/FarmerController::ensureUserCanAccessCourseLinkedGame → KILLED
        ensureUserCanAccessCourseLinkedGame(u, game);
117
118 1 1. putFarmerByIdBuy : negated conditional → KILLED
        if (game.isHidden()) {
119
          throw new GameHiddenException(gameId);
120
        }
121
122
        Farmer farmer = farmerRepository.findByGameIdAndUserId(gameId, userId)
123
        .orElseThrow(
124 1 1. lambda$putFarmerByIdBuy$1 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$putFarmerByIdBuy$1 → KILLED
            () -> new EntityNotFoundException(Farmer.class, "gameId", gameId, "userId", userId));
125
126 1 1. putFarmerByIdBuy : Replaced double addition with subtraction → KILLED
        double costPerCow = game.getCowPrice() + game.getPurchaseFee();
127 3 1. putFarmerByIdBuy : Replaced double multiplication with division → KILLED
2. putFarmerByIdBuy : negated conditional → KILLED
3. putFarmerByIdBuy : changed conditional boundary → KILLED
        if(farmer.getTotalWealth() >= (costPerCow * numCows)){
128 3 1. putFarmerByIdBuy : Replaced double multiplication with division → KILLED
2. putFarmerByIdBuy : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setTotalWealth → KILLED
3. putFarmerByIdBuy : Replaced double subtraction with addition → KILLED
          farmer.setTotalWealth(farmer.getTotalWealth() - (costPerCow * numCows));
129 2 1. putFarmerByIdBuy : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setNumOfCows → KILLED
2. putFarmerByIdBuy : Replaced integer addition with subtraction → KILLED
          farmer.setNumOfCows(farmer.getNumOfCows() + numCows);
130 2 1. putFarmerByIdBuy : Replaced integer addition with subtraction → KILLED
2. putFarmerByIdBuy : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowsBought → KILLED
          farmer.setCowsBought(farmer.getCowsBought() + numCows);
131
        }
132
        else{
133
          throw new NotEnoughMoneyException("You need more money!");
134
        }
135
        farmerRepository.save(farmer);
136 1 1. putFarmerByIdBuy : Replaced integer addition with subtraction → KILLED
        int herdNumber = herdRepository.findMaxHerdNumber(gameId, userId) + 1;
137
        herdRepository.save(Herd.builder().farmer(farmer).herdNumber(herdNumber).numCows(numCows).health(100).build());
138
139 1 1. putFarmerByIdBuy : removed call to edu/ucsb/cs156/happiercows/services/FarmerActivityService::recordActivityIfStudentMatch → KILLED
        farmerActivityService.recordActivityIfStudentMatch(
140
            u, game, farmer, FarmerActivity.ACTIVITY_TYPE_BUY, numCows);
141
142
        String body = mapper.writeValueAsString(farmer);
143 1 1. putFarmerByIdBuy : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::putFarmerByIdBuy → KILLED
        return ResponseEntity.ok().body(body);
144
    }
145
146
  /**
147
   * Sells cows from specific herds. The request body maps each herd id to the
148
   * number of cows to sell from that herd, e.g. {"12": 3, "15": 1}. Every herd
149
   * must belong to the current user in this game, and each count must be
150
   * between 0 and the number of cows in that herd. Each cow sells for the cow
151
   * price times its herd's health (as a percentage), minus the selling fee.
152
   * Herds that reach 0 cows are removed.
153
   */
154
  @Operation(summary = "Sell cows from specific herds, totalWealth updated")
155
  @PreAuthorize("hasRole('ROLE_USER')")
156
  @PutMapping("/sell")
157
  @Transactional
158
  public ResponseEntity<String> putFarmerByIdSell(
159
          @Parameter(name="gameId") @RequestParam Long gameId,
160
          @RequestBody Map<Long, Integer> herdCounts) throws NoCowsException, InvalidNumberOfCowsException, JsonProcessingException {
161
        User u = getCurrentUser().getUser();
162
        Long userId = u.getId();
163
164
        Game game = gameRepository.findById(gameId).orElseThrow( 
165 1 1. lambda$putFarmerByIdSell$0 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$putFarmerByIdSell$0 → KILLED
          ()->new EntityNotFoundException("Game", gameId));
166
167 1 1. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/controllers/FarmerController::ensureUserCanAccessCourseLinkedGame → KILLED
        ensureUserCanAccessCourseLinkedGame(u, game);
168
169 1 1. putFarmerByIdSell : negated conditional → KILLED
        if (game.isHidden()) {
170
          throw new GameHiddenException(gameId);
171
        }
172
173
        Farmer farmer = farmerRepository.findByGameIdAndUserId(gameId, userId)
174
        .orElseThrow(
175 1 1. lambda$putFarmerByIdSell$1 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$putFarmerByIdSell$1 → KILLED
            () -> new EntityNotFoundException(Farmer.class, "gameId", gameId, "userId", userId));
176
177
        // Only the current user's herds in this game can be sold from.
178
        Map<Long, Herd> herdsById = new HashMap<>();
179
        for (Herd herd : herdRepository.findByGameIdAndUserId(gameId, userId)) {
180
          herdsById.put(herd.getId(), herd);
181
        }
182
183
        // Validate every requested count before changing anything.
184
        int totalCows = 0;
185
        double totalValue = 0;
186
        for (Map.Entry<Long, Integer> entry : herdCounts.entrySet()) {
187
          Herd herd = herdsById.get(entry.getKey());
188 1 1. putFarmerByIdSell : negated conditional → KILLED
          if (herd == null) {
189
            throw new EntityNotFoundException(Herd.class, entry.getKey());
190
          }
191
          Integer count = entry.getValue();
192 3 1. putFarmerByIdSell : negated conditional → KILLED
2. putFarmerByIdSell : negated conditional → KILLED
3. putFarmerByIdSell : changed conditional boundary → KILLED
          if (count == null || count < 0) {
193
            throw new InvalidNumberOfCowsException("You cannot sell a negative number of cows!");
194
          }
195 2 1. putFarmerByIdSell : negated conditional → KILLED
2. putFarmerByIdSell : changed conditional boundary → KILLED
          if (count > herd.getNumCows()) {
196
            throw new NoCowsException("You do not have enough cows in that herd to sell!");
197
          }
198 2 1. putFarmerByIdSell : Replaced double division with multiplication → KILLED
2. putFarmerByIdSell : Replaced double multiplication with division → KILLED
          double cowValue = game.getCowPrice() * herd.getHealth() / 100
199 1 1. putFarmerByIdSell : Replaced double subtraction with addition → KILLED
              - game.getSellingFee();
200 1 1. putFarmerByIdSell : Replaced integer addition with subtraction → KILLED
          totalCows += count;
201 2 1. putFarmerByIdSell : Replaced double addition with subtraction → KILLED
2. putFarmerByIdSell : Replaced double multiplication with division → KILLED
          totalValue += cowValue * count;
202
        }
203 2 1. putFarmerByIdSell : changed conditional boundary → KILLED
2. putFarmerByIdSell : negated conditional → KILLED
        if (totalCows < 1) {
204
          throw new InvalidNumberOfCowsException("You must sell at least 1 cow!");
205
        }
206
207
        for (Map.Entry<Long, Integer> entry : herdCounts.entrySet()) {
208
          Herd herd = herdsById.get(entry.getKey());
209 1 1. putFarmerByIdSell : Replaced integer subtraction with addition → KILLED
          int remaining = herd.getNumCows() - entry.getValue();
210 1 1. putFarmerByIdSell : negated conditional → KILLED
          if (remaining == 0) {
211 1 1. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/repositories/HerdRepository::delete → KILLED
            herdRepository.delete(herd);
212 2 1. putFarmerByIdSell : negated conditional → KILLED
2. putFarmerByIdSell : changed conditional boundary → KILLED
          } else if (remaining < herd.getNumCows()) {
213 1 1. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/entities/Herd::setNumCows → KILLED
            herd.setNumCows(remaining);
214
            herdRepository.save(herd);
215
          }
216
        }
217
218 2 1. putFarmerByIdSell : Replaced double addition with subtraction → KILLED
2. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setTotalWealth → KILLED
        farmer.setTotalWealth(farmer.getTotalWealth() + totalValue);
219 2 1. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setNumOfCows → KILLED
2. putFarmerByIdSell : Replaced integer subtraction with addition → KILLED
        farmer.setNumOfCows(farmer.getNumOfCows() - totalCows);
220 2 1. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowsSold → KILLED
2. putFarmerByIdSell : Replaced integer addition with subtraction → KILLED
        farmer.setCowsSold(farmer.getCowsSold() + totalCows);
221
        farmerRepository.save(farmer);
222
223 1 1. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/services/FarmerActivityService::recordActivityIfStudentMatch → KILLED
        farmerActivityService.recordActivityIfStudentMatch(
224
            u, game, farmer, FarmerActivity.ACTIVITY_TYPE_SELL, totalCows);
225
226
        String body = mapper.writeValueAsString(farmer);
227 1 1. putFarmerByIdSell : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::putFarmerByIdSell → KILLED
        return ResponseEntity.ok().body(body);
228
    }
229
230
    
231
232
    @Operation(summary = "Get all user game for a specific game")
233
    @PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
234
    @GetMapping("/game/all")
235
    public List<FarmerWithStudentStatus> getFarmersByGameId(
236
        @Parameter(name="gameId") @RequestParam Long gameId) {
237
238
      Game game = gameRepository.findById(gameId)
239 1 1. lambda$getFarmersByGameId$0 : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$getFarmersByGameId$0 → KILLED
          .orElseThrow(() -> new EntityNotFoundException("Game", gameId));
240
241
      List<FarmerWithStudentStatus> result = new ArrayList<>();
242
      for (Farmer farmer : farmerRepository.findByGameId(gameId)) {
243
        boolean isStudent = courseAccessService
244
            .findMatchingStudentForCourseLinkedGame(farmer.getUser(), game)
245
            .isPresent();
246
247
        result.add(FarmerWithStudentStatus.builder()
248
            .userId(farmer.getUserId())
249
            .gameId(farmer.getGameId())
250
            .username(farmer.getUsername())
251
            .totalWealth(farmer.getTotalWealth())
252
            .numOfCows(farmer.getNumOfCows())
253
            .cowHealth(farmer.getCowHealth())
254
            .cowsBought(farmer.getCowsBought())
255
            .cowsSold(farmer.getCowsSold())
256
            .cowDeaths(farmer.getCowDeaths())
257
            .student(isStudent)
258
            .build());
259
      }
260 1 1. getFarmersByGameId : replaced return value with Collections.emptyList for edu/ucsb/cs156/happiercows/controllers/FarmerController::getFarmersByGameId → KILLED
      return result;
261
  }
262
263
  private void ensureUserCanAccessCourseLinkedGame(User user, Game game) {
264 2 1. ensureUserCanAccessCourseLinkedGame : negated conditional → KILLED
2. ensureUserCanAccessCourseLinkedGame : negated conditional → KILLED
    if (game.getCourseId() != null && !courseAccessService.isEligibleForGame(user, game)) {
265
      throw new NotEnrolledInCourseAssociatedWithGameException();
266
    }
267
  }
268
269
}

Mutations

78

1.1
Location : lambda$getFarmerById$0
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_getFarmerById_nonexists_admin()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$getFarmerById$0 → KILLED

79

1.1
Location : getFarmerById
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_getFarmerById_exists_admin()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::getFarmerById → KILLED

91

1.1
Location : lambda$getFarmerById$1
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_getFarmerById_when_game_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$getFarmerById$1 → KILLED

92

1.1
Location : getFarmerById
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_getFarmerById_course_linked_game_requires_current_enrollment()]
removed call to edu/ucsb/cs156/happiercows/controllers/FarmerController::ensureUserCanAccessCourseLinkedGame → KILLED

95

1.1
Location : lambda$getFarmerById$2
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_getFarmerById_nonexists()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$getFarmerById$2 → KILLED

96

1.1
Location : getFarmerById
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_getFarmerById_exists()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::getFarmerById → KILLED

106

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_hidden_game()]
changed conditional boundary → KILLED

2.2
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_negative_cows_rejected()]
negated conditional → KILLED

114

1.1
Location : lambda$putFarmerByIdBuy$0
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_buyCow_game_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$putFarmerByIdBuy$0 → KILLED

116

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_buyCow_course_linked_game_requires_current_enrollment()]
removed call to edu/ucsb/cs156/happiercows/controllers/FarmerController::ensureUserCanAccessCourseLinkedGame → KILLED

118

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_buyCow_for_user_not_in_game()]
negated conditional → KILLED

124

1.1
Location : lambda$putFarmerByIdBuy$1
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_buyCow_for_user_not_in_game()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$putFarmerByIdBuy$1 → KILLED

126

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_buyCow_chargesPurchaseFeePerCow()]
Replaced double addition with subtraction → KILLED

127

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_not_enough_money()]
Replaced double multiplication with division → KILLED

2.2
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_not_enough_money()]
negated conditional → KILLED

3.3
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_game_exists_user_has_exact_amount_needed()]
changed conditional boundary → KILLED

128

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_buyCow_chargesPurchaseFeePerCow()]
Replaced double multiplication with division → KILLED

2.2
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_game_exists_user_has_exact_amount_needed()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setTotalWealth → KILLED

3.3
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_game_exists_user_has_exact_amount_needed()]
Replaced double subtraction with addition → KILLED

129

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_game_exists_user_has_exact_amount_needed()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setNumOfCows → KILLED

2.2
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_game_exists_user_has_exact_amount_needed()]
Replaced integer addition with subtraction → KILLED

130

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_game_exists_user_has_exact_amount_needed()]
Replaced integer addition with subtraction → KILLED

2.2
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_game_exists_user_has_exact_amount_needed()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowsBought → KILLED

136

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_game_exists()]
Replaced integer addition with subtraction → KILLED

139

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_game_exists()]
removed call to edu/ucsb/cs156/happiercows/services/FarmerActivityService::recordActivityIfStudentMatch → KILLED

143

1.1
Location : putFarmerByIdBuy
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_BuyCow_game_exists_user_has_exact_amount_needed()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::putFarmerByIdBuy → KILLED

165

1.1
Location : lambda$putFarmerByIdSell$0
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_game_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$putFarmerByIdSell$0 → KILLED

167

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
removed call to edu/ucsb/cs156/happiercows/controllers/FarmerController::ensureUserCanAccessCourseLinkedGame → KILLED

169

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_for_user_not_in_game()]
negated conditional → KILLED

175

1.1
Location : lambda$putFarmerByIdSell$1
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_for_user_not_in_game()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$putFarmerByIdSell$1 → KILLED

188

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_missing_count_rejected()]
negated conditional → KILLED

192

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_negative_count_rejected()]
negated conditional → KILLED

2.2
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_missing_count_rejected()]
negated conditional → KILLED

3.3
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_zero_total_rejected()]
changed conditional boundary → KILLED

195

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_zero_total_rejected()]
negated conditional → KILLED

2.2
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
changed conditional boundary → KILLED

198

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
Replaced double division with multiplication → KILLED

2.2
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
Replaced double multiplication with division → KILLED

199

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_from_several_herds_uses_each_herds_health()]
Replaced double subtraction with addition → KILLED

200

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
Replaced integer addition with subtraction → KILLED

201

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
Replaced double addition with subtraction → KILLED

2.2
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
Replaced double multiplication with division → KILLED

203

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_herd_with_zero_requested_is_left_unchanged()]
changed conditional boundary → KILLED

2.2
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_empty_request_rejected()]
negated conditional → KILLED

209

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
Replaced integer subtraction with addition → KILLED

210

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
negated conditional → KILLED

211

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
removed call to edu/ucsb/cs156/happiercows/repositories/HerdRepository::delete → KILLED

212

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_herd_with_zero_requested_is_left_unchanged()]
negated conditional → KILLED

2.2
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_herd_with_zero_requested_is_left_unchanged()]
changed conditional boundary → KILLED

213

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_herd_with_zero_requested_is_left_unchanged()]
removed call to edu/ucsb/cs156/happiercows/entities/Herd::setNumCows → KILLED

218

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
Replaced double addition with subtraction → KILLED

2.2
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setTotalWealth → KILLED

219

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setNumOfCows → KILLED

2.2
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
Replaced integer subtraction with addition → KILLED

220

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowsSold → KILLED

2.2
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
Replaced integer addition with subtraction → KILLED

223

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_from_several_herds_uses_each_herds_health()]
removed call to edu/ucsb/cs156/happiercows/services/FarmerActivityService::recordActivityIfStudentMatch → KILLED

227

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_sellCows_course_linked_game_allows_current_enrollment()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::putFarmerByIdSell → KILLED

239

1.1
Location : lambda$getFarmersByGameId$0
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_getAllFarmerById_game_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$getFarmersByGameId$0 → KILLED

260

1.1
Location : getFarmersByGameId
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_getAllFarmerById_exists()]
replaced return value with Collections.emptyList for edu/ucsb/cs156/happiercows/controllers/FarmerController::getFarmersByGameId → KILLED

264

1.1
Location : ensureUserCanAccessCourseLinkedGame
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_buyCow_course_linked_game_requires_current_enrollment()]
negated conditional → KILLED

2.2
Location : ensureUserCanAccessCourseLinkedGame
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_getFarmerById_nonexists()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1