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.entities.User;
17
import edu.ucsb.cs156.happiercows.entities.Farmer;
18
import edu.ucsb.cs156.happiercows.entities.FarmerActivity;
19
import edu.ucsb.cs156.happiercows.entities.Game;
20
import edu.ucsb.cs156.happiercows.errors.EntityNotFoundException;
21
import edu.ucsb.cs156.happiercows.errors.NoCowsException;
22
import edu.ucsb.cs156.happiercows.errors.NotEnoughMoneyException;
23
import edu.ucsb.cs156.happiercows.errors.GameHiddenException;
24
import edu.ucsb.cs156.happiercows.errors.NotEnrolledInCourseAssociatedWithGameException;
25
import edu.ucsb.cs156.happiercows.models.FarmerWithStudentStatus;
26
import edu.ucsb.cs156.happiercows.services.CourseAccessService;
27
import edu.ucsb.cs156.happiercows.services.FarmerActivityService;
28
29
import java.util.ArrayList;
30
import java.util.List;
31
32
import io.swagger.v3.oas.annotations.tags.Tag;
33
import io.swagger.v3.oas.annotations.Operation;
34
import io.swagger.v3.oas.annotations.Parameter;
35
36
import org.springframework.http.ResponseEntity;
37
import org.springframework.web.bind.annotation.PutMapping;
38
39
@Tag(name = "User Game")
40
@RequestMapping("/api/farmer")
41
@RestController
42
public class FarmerController extends ApiController {
43
44
  @Autowired
45
  private FarmerRepository farmerRepository;
46
47
  @Autowired
48
  private GameRepository gameRepository;
49
50
  @Autowired
51
  ObjectMapper mapper;
52
53
  @Autowired
54
  private CourseAccessService courseAccessService;
55
56
  @Autowired
57
  private FarmerActivityService farmerActivityService;
58
59
  @Operation(summary = "Get a specific user game (admin only)")
60
  @PreAuthorize("hasRole('ROLE_ADMIN')")
61
  @GetMapping("")
62
  public Farmer getFarmerById(
63
      @Parameter(name="userId") @RequestParam Long userId,
64
      @Parameter(name="gameId") @RequestParam Long gameId) throws JsonProcessingException {
65
66
    Farmer farmer = farmerRepository.findByGameIdAndUserId(gameId, userId)
67
        .orElseThrow(
68 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));
69 1 1. getFarmerById : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::getFarmerById → KILLED
    return farmer;
70
  }
71
72
  @Operation(summary = "Get a user game for current user")
73
  @PreAuthorize("hasRole('ROLE_USER')")
74
  @GetMapping("/forcurrentuser")
75
  public Farmer getFarmerById(
76
      @Parameter(name="gameId") @RequestParam Long gameId) throws JsonProcessingException {
77
78
    User u = getCurrentUser().getUser();
79
    Long userId = u.getId();
80
    Game game = gameRepository.findById(gameId)
81 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));
82 1 1. getFarmerById : removed call to edu/ucsb/cs156/happiercows/controllers/FarmerController::ensureUserCanAccessCourseLinkedGame → KILLED
    ensureUserCanAccessCourseLinkedGame(u, game);
83
    Farmer farmer = farmerRepository.findByGameIdAndUserId(gameId, userId)
84
        .orElseThrow(
85 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));
86 1 1. getFarmerById : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::getFarmerById → KILLED
    return farmer;
87
  }
88
89
  @Operation(summary = "Buy a cow, totalWealth updated")
90
  @PreAuthorize("hasRole('ROLE_USER')")
91
  @PutMapping("/buy")
92
  public ResponseEntity<String> putFarmerByIdBuy(
93
          @Parameter(name="gameId") @RequestParam Long gameId,
94
          @Parameter(name="numCows") @RequestParam int numCows) throws NotEnoughMoneyException, JsonProcessingException{
95
96
        User u = getCurrentUser().getUser();
97
        Long userId = u.getId();
98
99
        Game game = gameRepository.findById(gameId).orElseThrow( 
100 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));
101
102 1 1. putFarmerByIdBuy : removed call to edu/ucsb/cs156/happiercows/controllers/FarmerController::ensureUserCanAccessCourseLinkedGame → KILLED
        ensureUserCanAccessCourseLinkedGame(u, game);
103
104 1 1. putFarmerByIdBuy : negated conditional → KILLED
        if (game.isHidden()) {
105
          throw new GameHiddenException(gameId);
106
        }
107
108
        Farmer farmer = farmerRepository.findByGameIdAndUserId(gameId, userId)
109
        .orElseThrow(
110 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));
111
112
113 2 1. putFarmerByIdBuy : Replaced double multiplication with division → KILLED
2. putFarmerByIdBuy : Replaced double addition with subtraction → KILLED
        double totalCost = (game.getCowPrice() + game.getPurchaseFee()) * numCows;
114
115 2 1. putFarmerByIdBuy : changed conditional boundary → KILLED
2. putFarmerByIdBuy : negated conditional → KILLED
        if (farmer.getTotalWealth() >= totalCost) {
116 2 1. putFarmerByIdBuy : Replaced double subtraction with addition → KILLED
2. putFarmerByIdBuy : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setTotalWealth → KILLED
          farmer.setTotalWealth(farmer.getTotalWealth() - totalCost);
117 2 1. putFarmerByIdBuy : Replaced integer addition with subtraction → KILLED
2. putFarmerByIdBuy : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setNumOfCows → KILLED
          farmer.setNumOfCows(farmer.getNumOfCows() + numCows);
118 2 1. putFarmerByIdBuy : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowsBought → KILLED
2. putFarmerByIdBuy : Replaced integer addition with subtraction → KILLED
          farmer.setCowsBought(farmer.getCowsBought() + numCows);
119
        } else {
120
          throw new NotEnoughMoneyException("You need more money!");
121
        }
122
123
        farmerRepository.save(farmer);
124
125 1 1. putFarmerByIdBuy : removed call to edu/ucsb/cs156/happiercows/services/FarmerActivityService::recordActivityIfStudentMatch → KILLED
        farmerActivityService.recordActivityIfStudentMatch(
126
            u, game, farmer, FarmerActivity.ACTIVITY_TYPE_BUY, numCows);
127
128
        String body = mapper.writeValueAsString(farmer);
129 1 1. putFarmerByIdBuy : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::putFarmerByIdBuy → KILLED
        return ResponseEntity.ok().body(body);
130
    }
131
132
  @Operation(summary = "Sell a cow, totalWealth updated")
133
  @PreAuthorize("hasRole('ROLE_USER')")
134
  @PutMapping("/sell")
135
  public ResponseEntity<String> putFarmerByIdSell(
136
          @Parameter(name="gameId") @RequestParam Long gameId,
137
          @Parameter(name="numCows") @RequestParam int numCows) throws NoCowsException, JsonProcessingException {
138
        User u = getCurrentUser().getUser();
139
        Long userId = u.getId();
140
141
        Game game = gameRepository.findById(gameId).orElseThrow( 
142 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));
143
144 1 1. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/controllers/FarmerController::ensureUserCanAccessCourseLinkedGame → KILLED
        ensureUserCanAccessCourseLinkedGame(u, game);
145
146 1 1. putFarmerByIdSell : negated conditional → KILLED
        if (game.isHidden()) {
147
          throw new GameHiddenException(gameId);
148
        }
149
150
        Farmer farmer = farmerRepository.findByGameIdAndUserId(gameId, userId)
151
        .orElseThrow(
152 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));
153
154
155 2 1. putFarmerByIdSell : negated conditional → KILLED
2. putFarmerByIdSell : changed conditional boundary → KILLED
        if (farmer.getNumOfCows() >= numCows) {
156 2 1. putFarmerByIdSell : Replaced double division with multiplication → KILLED
2. putFarmerByIdSell : Replaced double multiplication with division → KILLED
          double cowValue = game.getCowPrice() * farmer.getCowHealth() / 100;
157 2 1. putFarmerByIdSell : Replaced double subtraction with addition → KILLED
2. putFarmerByIdSell : Replaced double multiplication with division → KILLED
          double totalRevenue = (cowValue - game.getSellingFee()) * numCows;
158
159 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() + totalRevenue);
160 2 1. putFarmerByIdSell : Replaced integer subtraction with addition → KILLED
2. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setNumOfCows → KILLED
          farmer.setNumOfCows(farmer.getNumOfCows() - numCows);
161 2 1. putFarmerByIdSell : Replaced integer addition with subtraction → KILLED
2. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowsSold → KILLED
          farmer.setCowsSold(farmer.getCowsSold() + numCows);
162
        } else {
163
          throw new NoCowsException("You do not have enough cows to sell!");
164
        }
165
166
        farmerRepository.save(farmer);
167
168 1 1. putFarmerByIdSell : removed call to edu/ucsb/cs156/happiercows/services/FarmerActivityService::recordActivityIfStudentMatch → KILLED
        farmerActivityService.recordActivityIfStudentMatch(
169
            u, game, farmer, FarmerActivity.ACTIVITY_TYPE_SELL, numCows);
170
171
        String body = mapper.writeValueAsString(farmer);
172 1 1. putFarmerByIdSell : replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::putFarmerByIdSell → KILLED
        return ResponseEntity.ok().body(body);
173
    }
174
175
    
176
177
    @Operation(summary = "Get all user game for a specific game")
178
    @PreAuthorize("hasAnyRole('ROLE_USER', 'ROLE_ADMIN')")
179
    @GetMapping("/game/all")
180
    public List<FarmerWithStudentStatus> getFarmersByGameId(
181
        @Parameter(name="gameId") @RequestParam Long gameId) {
182
183
      Game game = gameRepository.findById(gameId)
184 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));
185
186
      List<FarmerWithStudentStatus> result = new ArrayList<>();
187
      for (Farmer farmer : farmerRepository.findByGameId(gameId)) {
188
        boolean isStudent = courseAccessService
189
            .findMatchingStudentForCourseLinkedGame(farmer.getUser(), game)
190
            .isPresent();
191
192
        result.add(FarmerWithStudentStatus.builder()
193
            .userId(farmer.getUserId())
194
            .gameId(farmer.getGameId())
195
            .username(farmer.getUsername())
196
            .totalWealth(farmer.getTotalWealth())
197
            .numOfCows(farmer.getNumOfCows())
198
            .cowHealth(farmer.getCowHealth())
199
            .cowsBought(farmer.getCowsBought())
200
            .cowsSold(farmer.getCowsSold())
201
            .cowDeaths(farmer.getCowDeaths())
202
            .student(isStudent)
203
            .build());
204
      }
205 1 1. getFarmersByGameId : replaced return value with Collections.emptyList for edu/ucsb/cs156/happiercows/controllers/FarmerController::getFarmersByGameId → KILLED
      return result;
206
  }
207
208
  private void ensureUserCanAccessCourseLinkedGame(User user, Game game) {
209 2 1. ensureUserCanAccessCourseLinkedGame : negated conditional → KILLED
2. ensureUserCanAccessCourseLinkedGame : negated conditional → KILLED
    if (game.getCourseId() != null && !courseAccessService.isEligibleForGame(user, game)) {
210
      throw new NotEnrolledInCourseAssociatedWithGameException();
211
    }
212
  }
213
214
}

Mutations

68

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

69

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

81

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

82

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

85

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

86

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

100

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

102

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

104

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

110

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

113

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_purchase_fee_causes_insufficient_funds()]
Replaced double addition with subtraction → KILLED

115

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()]
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_game_exists_not_enough_money()]
negated conditional → 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_zero_purchase_fee_preserves_existing_cost()]
Replaced double subtraction with addition → 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_zero_purchase_fee_preserves_existing_cost()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setTotalWealth → KILLED

117

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_zero_purchase_fee_preserves_existing_cost()]
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_zero_purchase_fee_preserves_existing_cost()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setNumOfCows → 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_with_purchase_fee_for_two_cows()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowsBought → 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_with_purchase_fee_for_two_cows()]
Replaced integer addition with subtraction → KILLED

125

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

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_with_purchase_fee_for_two_cows()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::putFarmerByIdBuy → KILLED

142

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_sellCow_game_does_not_exist()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$putFarmerByIdSell$0 → KILLED

144

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

146

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

152

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_sellCow_for_user_not_in_game()]
replaced return value with null for edu/ucsb/cs156/happiercows/controllers/FarmerController::lambda$putFarmerByIdSell$1 → KILLED

155

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_SellCow_game_exists_no_cow_to_sell()]
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_SellCow_with_selling_fee_and_partial_health()]
changed conditional boundary → KILLED

156

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_SellCow_with_selling_fee_and_partial_health()]
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_SellCow_with_selling_fee_and_partial_health()]
Replaced double multiplication with division → KILLED

157

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_SellCow_with_selling_fee_and_partial_health()]
Replaced double subtraction with addition → 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_SellCow_with_selling_fee_and_partial_health()]
Replaced double multiplication with division → KILLED

159

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_SellCow_with_selling_fee_and_partial_health()]
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_SellCow_with_selling_fee_and_partial_health()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setTotalWealth → KILLED

160

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_SellCow_with_selling_fee_and_partial_health()]
Replaced integer subtraction with addition → 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_SellCow_with_selling_fee_and_partial_health()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setNumOfCows → KILLED

161

1.1
Location : putFarmerByIdSell
Killed by : edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.happiercows.controllers.FarmerControllerTests]/[method:test_SellCow_with_selling_fee_and_partial_health()]
Replaced integer 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_SellCow_with_selling_fee_and_partial_health()]
removed call to edu/ucsb/cs156/happiercows/entities/Farmer::setCowsSold → KILLED

168

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

172

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

184

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

205

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

209

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_buyCow_for_user_not_in_game()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1