Skip to content

Commit

Permalink
MORE-562: fixed testing error
Browse files Browse the repository at this point in the history
  • Loading branch information
drtyyj committed Jun 23, 2023
1 parent 3b6c743 commit 6c435d4
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.redlink.more.studymanager.service;

import io.redlink.more.studymanager.configuration.TimezoneConfiguration;
import io.redlink.more.studymanager.exception.BadRequestException;
import io.redlink.more.studymanager.model.Event;
import io.redlink.more.studymanager.model.Timeframe;
Expand All @@ -11,6 +12,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ContextConfiguration;

import java.time.Instant;
import java.time.LocalDate;
Expand All @@ -20,8 +25,13 @@
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ExtendWith(MockitoExtension.class)
@SpringBootTest
@ContextConfiguration(initializers = ScheduleServiceTest.EnvInitializer.class,
classes = {
ScheduleService.class,
TimezoneConfiguration.class,
})
public class ScheduleServiceTest {

@MockBean
Expand Down Expand Up @@ -62,4 +72,14 @@ void testAssertFails() {
assertThrows(BadRequestException.class, () -> scheduleService.assertScheduleWithinStudyTime(1L, scheduleBefore));
assertThrows(BadRequestException.class, () -> scheduleService.assertScheduleWithinStudyTime(1L, scheduleAfter));
}

static class EnvInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {

@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
TestPropertyValues.of(
"more.timeframe.identifier=Europe/Vienna"
).applyTo(applicationContext);
}
}
}

0 comments on commit 6c435d4

Please sign in to comment.