Skip to content

Commit

Permalink
Fix 'System.setProperty()' issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuznik committed Dec 10, 2024
1 parent 6d68a78 commit 6e55228
Showing 1 changed file with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;

Expand All @@ -21,39 +22,40 @@ class SMSLimitServiceTest {
@MockBean
SMSLimitRepository smsLimitRepository;

// @Test
// void shouldReturnLimitNotReach() {
// //given
// System.setProperty("DAY_SMS_LIMIT", "10");
// SMSLimit smsLimit = SMSLimit.builder()
// .limitCounter(0)
// .build();
//
// //when
// when(smsLimitRepository.findByExactDay(any(LocalDateTime.class))).thenReturn(Optional.of(smsLimit));
//
// //then
// boolean belowLimit = smsLimitService.isBelowLimit(LocalDateTime.now());
//
// assertThat(belowLimit).isTrue();
// }
//
// @Test
// void shouldReturnLimitIsReach() {
// //given
// System.setProperty("DAY_SMS_LIMIT", "10");
// SMSLimit smsLimit = SMSLimit.builder()
// .limitCounter(10)
// .build();
//
// //when
// when(smsLimitRepository.findByExactDay(any(LocalDateTime.class))).thenReturn(Optional.of(smsLimit));
//
// //then
// boolean belowLimit = smsLimitService.isBelowLimit(LocalDateTime.now());
//
// assertThat(belowLimit).isFalse();
// }
@Value("${day.sms.limit}")
private String daySmsLimit;

@Test
void shouldReturnLimitNotReach() {
//given
SMSLimit smsLimit = SMSLimit.builder()
.limitCounter(0)
.build();

//when
when(smsLimitRepository.findByExactDay(any(LocalDateTime.class))).thenReturn(Optional.of(smsLimit));

//then
boolean belowLimit = smsLimitService.isBelowLimit(LocalDateTime.now());

assertThat(belowLimit).isTrue();
}

@Test
void shouldReturnLimitIsReach() {
//given
SMSLimit smsLimit = SMSLimit.builder()
.limitCounter(Integer.parseInt(daySmsLimit))
.build();

//when
when(smsLimitRepository.findByExactDay(any(LocalDateTime.class))).thenReturn(Optional.of(smsLimit));

//then
boolean belowLimit = smsLimitService.isBelowLimit(LocalDateTime.now());

assertThat(belowLimit).isFalse();
}

@Test
void shouldCreateNewLimiter_whenNeededLimiterNotExist() {
Expand Down

0 comments on commit 6e55228

Please sign in to comment.