Skip to content

Commit

Permalink
Test : 실패 테스트 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
byeolhaha committed Oct 27, 2023
1 parent 31c1ab3 commit 33f54c6
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 13 deletions.
41 changes: 41 additions & 0 deletions src/main/java/org/guzzing/studay_server/Report.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.guzzing.studay_server;

import jakarta.persistence.*;
import lombok.*;
import org.springframework.util.Assert;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Report {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="report_id")
private Long id;

@Column(nullable = false)
private Long postId;

@Column(nullable = false)
private Long reporterId;

@Column
private String contents;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private ReportItem item;

public Report(Long postId, Long reporterId, String contents, ReportItem item) {
Assert.notNull(postId,"게시글 Id는 null이 들어올 수 없습니다.");
Assert.notNull(reporterId,"신고자의 Id는 null이 들어올 수 없습니다");
Assert.notNull(item,"신고항목은 null이 들어올 수 없습니다.");

this.postId = postId;
this.reporterId = reporterId;
this.contents = contents;
this.item = item;
}

}
33 changes: 33 additions & 0 deletions src/main/java/org/guzzing/studay_server/ReportItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.guzzing.studay_server;

import org.springframework.data.crossstore.ChangeSetPersister;

import java.util.Arrays;

public enum ReportItem {
FAKED_SALE("허위 매물", 5),
SPAMMING("도배글", 1),
SWEAR_WORD("욕설", 3),
SENSATIONAL("선정성", 5),
PERSONAL_INFORMATION_EXPOSURE("개인정보노출", 2),
COMMENTS("기타사항",1);

private final String description;
private final int score;

ReportItem(String description, int score) {
this.description = description;
this.score = score;
}

public int getScore() {
return score;
}

public static ReportItem find(String reportItem) throws ChangeSetPersister.NotFoundException {
return Arrays.stream(ReportItem.values()).filter(r->r.equals(reportItem)).
findFirst().orElseThrow(()-> new ChangeSetPersister.NotFoundException());
}

}

50 changes: 50 additions & 0 deletions src/test/java/org/guzzing/studay_server/ReportTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.guzzing.studay_server;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class ReportTest {

@Test
@DisplayName("!!필수로 들어가야 하는 게시글 id가 들어가지 않은 경우 예외를 던진다. 롤루")
public void createReport_nullPostId_throwIllegalArgumentException() {
//given
Long postId = null;
Long reporterId = 2L;
String contents = "This is a report.";
ReportItem item = ReportItem.FAKED_SALE;

//when_then
assertThrows(IllegalArgumentException.class,()->new Report(postId, reporterId, contents, item));
}

@Test
@DisplayName("필수로 들어가야 하는 신고자 id가 들어가지 않는 경우 예외를 던진다.")
public void createReport_nullReporterId_throwIllegalArgumentException() {
//given
Long postId = 1L;
Long reporterId = 2L;
String contents = "This is a report.";
ReportItem item = ReportItem.FAKED_SALE;

//when_then
assertThrows(IllegalArgumentException.class,()->new Report(postId, reporterId, contents, item));
}

@Test
@DisplayName("필수로 들어가야 하는 신고 항목이 들어가지 않은 경우 예외를 던진다.")
public void createReport_nullItem_throwIllegalArgumentException() {
//given
Long postId = 1L;
Long reporterId = 2L;
String contents = "This is a report.";
ReportItem item = null;

//when_then
assertThrows(IllegalArgumentException.class,()->new Report(postId, reporterId, contents, item));
}
}


This file was deleted.

0 comments on commit 33f54c6

Please sign in to comment.