Skip to content

Commit

Permalink
[kiworkshop#62] add TagContent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jiwookim5757 committed Apr 8, 2020
1 parent 4785e72 commit f5391b7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
14 changes: 12 additions & 2 deletions tag-api/src/main/java/community/tag/domain/TagContent.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package community.tag.domain;

import community.common.model.BaseEntity;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.util.Assert;

import javax.persistence.*;

@Getter
@Entity
@NoArgsConstructor
public class TagContent {
public class TagContent extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand All @@ -20,7 +22,15 @@ public class TagContent {
private Long contentId;

@Builder
private TagContent(Tag tag, String contentType, Long contentId) {
private TagContent(
Tag tag,
String contentType,
Long contentId
) {
Assert.notNull(tag, "tag should not be null.");
Assert.hasLength(contentType, "contentType should not be empty.");
Assert.notNull(contentId, "contentId should not be null.");

this.tag = tag;
this.contentType = contentType;
this.contentId = contentId;
Expand Down
42 changes: 33 additions & 9 deletions tag-api/src/test/java/community/tag/domain/TagContentTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package community.tag.domain;

//import community.table.domain.ContentTable;
import org.junit.jupiter.api.Test;

import static community.tag.domain.TagTest.getTagFixture;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.BDDAssertions.thenThrownBy;

class ContentTableTest {
class TagContentTest {

@Test
void build_ValidInput_ValidOutput() {
Expand All @@ -31,17 +29,43 @@ void build_ValidInput_ValidOutput() {
}

@Test
void build_EmptyContentType_ThrowException() {
// given
Tag tag = getTagFixture();

void build_NullTag_ThrowException() {
// then
thenThrownBy(() ->
TagContent.builder()
.tag(tag)
.contentType("")
.tag(null)
.contentType("simplelife")
.contentId(1L).build()
).isInstanceOf(IllegalArgumentException.class);
}


@Test
void build_EmptyContentType_ThrowException() {
// given
Tag tag = getTagFixture();

// then
thenThrownBy(() ->
TagContent.builder()
.tag(tag)
.contentType("")
.contentId(1L).build()
).isInstanceOf(IllegalArgumentException.class);
}


@Test
void build_NullContentId_ThrowException() {
// given
Tag tag = getTagFixture();

// then
thenThrownBy(() ->
TagContent.builder()
.tag(tag)
.contentType("simplelife")
.contentId(null).build()
).isInstanceOf(IllegalArgumentException.class);
}
}

0 comments on commit f5391b7

Please sign in to comment.