Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 3주차 테스트 코드 제출 #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
60 changes: 13 additions & 47 deletions .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 13 additions & 47 deletions .idea/sonarlint/securityhotspotstore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.seminar.common.exception;

public class MemberException extends RuntimeException {
public class MemberException extends BusinessException {
public MemberException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.example.seminar.common.exception;

public class PostException extends RuntimeException {
public class PostException extends BusinessException {
public PostException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.seminar.controller;


import com.example.seminar.common.exception.MemberException;
import com.example.seminar.dto.request.member.MemberCreateRequest;
import com.example.seminar.dto.request.member.MemberProfileUpdateRequest;
import com.example.seminar.dto.response.MemberGetResponse;
Expand All @@ -22,7 +23,7 @@ public class MemberController {

@PostMapping
public ResponseEntity<Void> createMember(@RequestBody MemberCreateRequest request) {
URI location = URI.create(memberService.create(request));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅋㅋㅋ 아 띄어쓰기..!!

URI location = URI.create(memberService.create(request));
return ResponseEntity.created(location).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class PostController {
public ResponseEntity<Void> createPost(
@RequestHeader(CUSTOM_AUTH_ID) Long memberId,
@RequestBody PostCreateRequest request) {
URI location = URI.create("/api/post/" + postService.create(request, memberId));
URI location = URI.create("/api/posts/" + postService.create(request, memberId));
return ResponseEntity.created(location).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class Member extends BaseTimeEntity {
private String name;
private String nickname;
private int age;
private boolean isDeleted = false;

@Embedded
private SOPT sopt;
Expand Down Expand Up @@ -81,4 +82,8 @@ public void addPosts(Post post){
public void updateSOPT(SOPT sopt) {
this.sopt = sopt;
}

public void remove(){
this.isDeleted = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.seminar.config;

import static org.mockito.Mockito.mock;

import org.junit.platform.commons.util.ClassFilter;
import org.junit.platform.commons.util.ReflectionUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.stereotype.Service;

public class MockAllServiceBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 진짜 신기하네요..

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
ClassFilter classFilter = ClassFilter.of(clazz -> clazz.isAnnotationPresent(Service.class));
ReflectionUtils.findAllClassesInPackage("com.example", classFilter)
.forEach(clazz -> {
AbstractBeanDefinition bean = BeanDefinitionBuilder
.genericBeanDefinition(clazz)
.getBeanDefinition();
registry.registerBeanDefinition(clazz.getSimpleName(), bean);
beanFactory.registerSingleton(clazz.getSimpleName(), mock(clazz));
});
}
}
Loading