Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ public enum SoundType {
private final String description;

public static SoundType from(String description) {
if (description == null) {
return NONE;
}

return Arrays.stream(values())
.filter(s -> s.description.equals(description))
.findFirst()
.orElse(null);
.orElse(NONE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.time.LocalTime;
import java.util.List;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Builder.Default;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
Expand Down Expand Up @@ -51,9 +53,10 @@ public class AlarmEntity extends BaseTimeEntity {
@Column(name = "repeat_days", columnDefinition = "TEXT", nullable = false)
private List<Weekday> repeatDays;

@Builder.Default
@Enumerated(EnumType.STRING)
@Column(name = "sound_type", length = 20, nullable = false)
private SoundType soundType;
private SoundType soundType = SoundType.NONE;

@Column(nullable = false)
private Double latitude;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package akuma.whiplash.domains.alarm.domain.constant;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

@DisplayName("SoundType - 소리 유형 변환")
class SoundTypeTest {

@ParameterizedTest
@CsvSource({
"소리 없음,NONE",
"알람 소리1,ONE",
"알람 소리2,TWO",
"알람 소리3,THREE",
"알람 소리4,FOUR"
})
@DisplayName("설명과 일치하는 소리 유형을 반환한다")
void returnsMatchingSoundType(String description, SoundType expected) {
// given

// when
SoundType soundType = SoundType.from(description);

// then
assertThat(soundType).isEqualTo(expected);
}

@Test
@DisplayName("존재하지 않는 설명을 입력하면 NONE으로 매핑된다")
void returnsNoneWhenDescriptionInvalid() {
// given
String description = "잘못된 소리";

// when
SoundType soundType = SoundType.from(description);

// then
assertThat(soundType).isEqualTo(SoundType.NONE);
}

@Test
@DisplayName("null을 입력하면 NONE으로 매핑된다")
void returnsNoneWhenDescriptionIsNull() {
// given
String description = null;

// when
SoundType soundType = SoundType.from(description);

// then
assertThat(soundType).isEqualTo(SoundType.NONE);
}
}