-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
허원철/NSC서버팀/NE
committed
Jan 1, 2025
1 parent
d3e11ce
commit 32cbeed
Showing
3 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
SpringBootTest/src/test/java/com/example/TestBeanTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.example; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.example.domain.TestMessage; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.test.context.bean.override.convention.TestBean; | ||
|
||
import com.example.service.BasicService; | ||
|
||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
public class TestBeanTest { | ||
|
||
@Autowired | ||
TestRestTemplate restTemplate; | ||
|
||
@TestBean | ||
BasicService basicService; | ||
|
||
static BasicService basicService() { | ||
return new BasicService() { | ||
@Override | ||
public String test(int flag) { | ||
return "Spring Boot Service Test"; | ||
} | ||
|
||
@Override | ||
public TestMessage jsonTest() { | ||
throw new UnsupportedOperationException("jsonTest not implemented"); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void mvcTest() { | ||
final String result = restTemplate.getForObject("/test?flag=0", String.class); | ||
assertThat(result) | ||
.isEqualTo("Spring Boot Service Test"); | ||
} | ||
|
||
@Test | ||
public void serviceTest() { | ||
assertThat(basicService.test(0)) | ||
.isEqualTo("Spring Boot Service Test"); | ||
} | ||
} |