NotificationService.java

1
package com.edtech.service;
2
3
import org.slf4j.Logger;
4
import org.slf4j.LoggerFactory;
5
import org.springframework.messaging.simp.SimpMessagingTemplate;
6
import org.springframework.stereotype.Service;
7
8
/** Javadoc. */
9
@Service
10
public class NotificationService {
11
12
  private static final Logger logger = LoggerFactory.getLogger(NotificationService.class);
13
  private final SimpMessagingTemplate messagingTemplate;
14
15
  public NotificationService(
16
      @org.springframework.beans.factory.annotation.Autowired(required = false)
17
          SimpMessagingTemplate messagingTemplate) {
18
    this.messagingTemplate = messagingTemplate;
19
  }
20
21
  /**
22
   * Envia uma notificação em tempo real (WebSocket) para um usuário específico.
23
   *
24
   * @param userId O ID do usuário (como String)
25
   * @param payload O conteúdo da mensagem
26
   */
27
  public void sendToUser(String userId, Object payload) {
28 1 1. sendToUser : negated conditional → KILLED
    if (messagingTemplate == null) {
29
      return;
30
    }
31
    String destination = "/queue/notifications";
32
    logger.info("Enviando notificacao WS para o usuario {}: {}", userId, payload);
33 1 1. sendToUser : removed call to org/springframework/messaging/simp/SimpMessagingTemplate::convertAndSendToUser → KILLED
    messagingTemplate.convertAndSendToUser(userId, destination, payload);
34
  }
35
36
  /**
37
   * Envia uma notificação para um tópico geral.
38
   *
39
   * @param topic O tópico de destino (ex: /topic/global)
40
   * @param payload O conteúdo da mensagem
41
   */
42
  public void sendToTopic(String topic, Object payload) {
43 1 1. sendToTopic : negated conditional → KILLED
    if (messagingTemplate == null) {
44
      return;
45
    }
46
    logger.info("Enviando notificacao WS global para o topico {}: {}", topic, payload);
47 1 1. sendToTopic : removed call to org/springframework/messaging/simp/SimpMessagingTemplate::convertAndSend → KILLED
    messagingTemplate.convertAndSend(topic, payload);
48
  }
49
}

Mutations

28

1.1
Location : sendToUser
Killed by : com.edtech.service.NotificationServiceTest.[engine:junit-jupiter]/[class:com.edtech.service.NotificationServiceTest]/[method:sendToUser_WhenTemplateIsNull_ShouldNotSend()]
negated conditional → KILLED

33

1.1
Location : sendToUser
Killed by : com.edtech.service.NotificationServiceTest.[engine:junit-jupiter]/[class:com.edtech.service.NotificationServiceTest]/[method:sendToUser_WhenTemplateIsNotNull_ShouldSend()]
removed call to org/springframework/messaging/simp/SimpMessagingTemplate::convertAndSendToUser → KILLED

43

1.1
Location : sendToTopic
Killed by : com.edtech.service.NotificationServiceTest.[engine:junit-jupiter]/[class:com.edtech.service.NotificationServiceTest]/[method:sendToTopic_WhenTemplateIsNull_ShouldNotSend()]
negated conditional → KILLED

47

1.1
Location : sendToTopic
Killed by : com.edtech.service.NotificationServiceTest.[engine:junit-jupiter]/[class:com.edtech.service.NotificationServiceTest]/[method:sendToTopic_WhenTemplateIsNotNull_ShouldSend()]
removed call to org/springframework/messaging/simp/SimpMessagingTemplate::convertAndSend → KILLED

Active mutators

Tests examined


Report generated by PIT 1.16.1