From ce85ba5d185f56dac5404e5f92a2148e70d0293c Mon Sep 17 00:00:00 2001 From: suhyunsim Date: Tue, 29 Dec 2020 15:01:14 +0900 Subject: [PATCH] test: Test code for ProfileController Issue #35 --- .../controller/ProfileControllerUnitTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/test/java/com/poogle/phog/web/profile/controller/ProfileControllerUnitTest.java diff --git a/src/test/java/com/poogle/phog/web/profile/controller/ProfileControllerUnitTest.java b/src/test/java/com/poogle/phog/web/profile/controller/ProfileControllerUnitTest.java new file mode 100644 index 0000000..b361c4d --- /dev/null +++ b/src/test/java/com/poogle/phog/web/profile/controller/ProfileControllerUnitTest.java @@ -0,0 +1,59 @@ +package com.poogle.phog.web.profile.controller; + +import org.junit.Test; +import org.springframework.mock.env.MockEnvironment; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ProfileControllerUnitTest { + + @Test + public void deploy_profile이_조회된다() { + //given + String expectedProfile = "deploy"; + MockEnvironment env = new MockEnvironment(); + env.addActiveProfile(expectedProfile); + env.addActiveProfile("oauth"); + env.addActiveProfile("real-db"); + + ProfileController controller = new ProfileController(env); + + //when + String profile = controller.profile(); + + //then + assertThat(profile).isEqualTo(expectedProfile); + } + + @Test + public void deploy_profile이_없으면_첫_번째가_조회된다() { + //given + String expactedProfile = "oauth"; + MockEnvironment env = new MockEnvironment(); + + env.addActiveProfile(expactedProfile); + env.addActiveProfile("real"); + + ProfileController controller = new ProfileController(env); + + //when + String profile = controller.profile(); + + //then + assertThat(profile).isEqualTo(expactedProfile); + } + + @Test + public void active_profile이_없으면_default가_조회된다() { + //given + String expectedProfile = "default"; + MockEnvironment env = new MockEnvironment(); + ProfileController controller = new ProfileController(env); + + //when + String profile = controller.profile(); + + //then + assertThat(profile).isEqualTo(expectedProfile); + } +}