FrontiersStartup.java

1
package edu.ucsb.cs156.frontiers.startup;
2
3
import edu.ucsb.cs156.frontiers.entities.Admin;
4
import edu.ucsb.cs156.frontiers.repositories.AdminRepository;
5
import java.util.List;
6
import lombok.extern.slf4j.Slf4j;
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.beans.factory.annotation.Value;
9
import org.springframework.stereotype.Component;
10
11
/** This class contains a `run` method that is called once at application startup time. */
12
@Slf4j
13
@Component
14
public class FrontiersStartup {
15
16
  @Value("#{'${app.admin.emails}'.split(',')}")
17
  List<String> adminEmails;
18
19
  @Value("${app.webhook.secret}")
20
  String webhookSecret;
21
22
  @Autowired AdminRepository adminRepository;
23
24
  /**
25
   * Called once at application startup time . Put code here if you want it to run once each time
26
   * the Spring Boot application starts up in all environments.
27
   */
28
  public void alwaysRunOnStartup() {
29
    log.info("alwaysRunOnStartup called");
30
31 1 1. alwaysRunOnStartup : removed call to edu/ucsb/cs156/frontiers/startup/FrontiersStartup::validateWebhookSecret → KILLED
    validateWebhookSecret();
32
33
    try {
34 1 1. alwaysRunOnStartup : removed call to java/util/List::forEach → KILLED
      adminEmails.forEach(
35
          (email) -> {
36
            Admin admin = new Admin(email);
37
            adminRepository.save(admin);
38
          });
39
    } catch (Exception e) {
40
      log.error("Error in loading all ADMIN_EMAILS:", e);
41
    }
42
  }
43
44
  private void validateWebhookSecret() {
45 3 1. validateWebhookSecret : negated conditional → KILLED
2. validateWebhookSecret : negated conditional → KILLED
3. validateWebhookSecret : changed conditional boundary → KILLED
    if (webhookSecret == null || webhookSecret.length() < 10) {
46
      String error =
47
          String.format(
48
              "WEBHOOK_SECRET must be at least 10 characters long. Current length: %d",
49 1 1. validateWebhookSecret : negated conditional → KILLED
              webhookSecret == null ? 0 : webhookSecret.length());
50
      log.error(error);
51
      throw new IllegalStateException(error);
52
    }
53
    log.info("Webhook secret validation passed");
54
  }
55
}

Mutations

31

1.1
Location : alwaysRunOnStartup
Killed by : edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests]/[method:test_AlwaysRunOnStartup_fails_with_null_webhook_secret()]
removed call to edu/ucsb/cs156/frontiers/startup/FrontiersStartup::validateWebhookSecret → KILLED

34

1.1
Location : alwaysRunOnStartup
Killed by : edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests]/[method:test_AlwaysRunOnStartup_handles_exception()]
removed call to java/util/List::forEach → KILLED

45

1.1
Location : validateWebhookSecret
Killed by : edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests]/[method:test_AlwaysRunOnStartup_fails_with_null_webhook_secret()]
negated conditional → KILLED

2.2
Location : validateWebhookSecret
Killed by : edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests]/[method:test_AlwaysRunOnStartup_fails_with_short_webhook_secret()]
negated conditional → KILLED

3.3
Location : validateWebhookSecret
Killed by : edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests]/[method:test_AlwaysRunOnStartup_succeeds_with_minimum_length_webhook_secret()]
changed conditional boundary → KILLED

49

1.1
Location : validateWebhookSecret
Killed by : edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests.[engine:junit-jupiter]/[class:edu.ucsb.cs156.frontiers.startup.FrontiersStartupTests]/[method:test_AlwaysRunOnStartup_fails_with_null_webhook_secret()]
negated conditional → KILLED

Active mutators

Tests examined


Report generated by PIT 1.17.0