/
marie.sidorkina
/
eye_tracking_java
Обзор
Документация
Войти
/
marie.sidorkina
/
eye_tracking_java
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/test/java/com/example/mydemo1/HintServiceTest.java
86 строк
3 KB
Marie
add tests
14 янв 2026, 11:17
14 янв 2026, 11:17
c2fa01e
Код
Авторство
О чём код?
package com.example.mydemo1; import com.example.mydemo1.model.*; import com.example.mydemo1.repository.UserRepository; import com.example.mydemo1.repository.SessionRepository; import com.example.mydemo1.service.HintService; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.time.Instant; import java.util.UUID; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; @SpringBootTest class HintServiceTest { @Autowired private HintService hintService; @Autowired private SessionRepository sessionRepository; @Autowired private UserRepository userRepository; @Test void shouldCreateHintForRegression() { User user = userRepository.save(createUser()); Session session = sessionRepository.save(createSession(user)); Chunk chunk = new Chunk(); chunk.setSession(session); chunk.setElementFrom("p.line1"); chunk.setElementTo("p.line2"); Prediction prediction = new Prediction(); prediction.setChunk(chunk); prediction.setStatus(PredictionStatus.CLASSIFIED_REGRESSION); prediction.setMetadataJson("{}"); Hint hint = hintService.createHint(prediction); assertNotNull(hint.getId(), "Hint id must not be null"); assertEquals(HintEvent.USER_REGRESSION_DETECTED, hint.getEvent(), "Hint event should be USER_REGRESSION_DETECTED for regression"); assertEquals(HintAction.HIGHLIGHT_ELEMENT, hint.getAction(), "Hint action should be HIGHLIGHT_ELEMENT for regression"); assertEquals("p.line1", hint.getTargetElement(), "Target element should be p.line1"); } @Test void shouldCreateHintForRead() { User user = userRepository.save(createUser()); Session session = sessionRepository.save(createSession(user)); Chunk chunk = new Chunk(); chunk.setSession(session); Prediction prediction = new Prediction(); prediction.setChunk(chunk); prediction.setStatus(PredictionStatus.CLASSIFIED_READ); Hint hint = hintService.createHint(prediction); assertEquals(HintEvent.USER_READING, hint.getEvent(), "Hint event should be USER_READING for read"); assertEquals(HintAction.NO_ACTION, hint.getAction(), "Hint action should be NO_ACTION for read"); } private @NotNull User createUser() { User u = new User(); u.setUsername("test"); u.setEmail("test" + UUID.randomUUID() + "@mail.com"); u.setPassword("123"); return u; } private @NotNull Session createSession(User user) { Session s = new Session(); s.setName("Test session"); s.setStartedAt(Instant.now()); s.setUser(user); return s; } }