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

[ST-5] Noti_수가_맞는_걸_확인 - 이시훈 #17

Open
wants to merge 1 commit into
base: master
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
22 changes: 22 additions & 0 deletions src/main/java/net/slipp/todo_list/CountableNotiManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package net.slipp.todo_list;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

@Primary
@Component
public class CountableNotiManager extends NotiManager {

private int callCount = 0;

public int getCallCount() {
return this.callCount;
}

@Override
public void notify(String notiMessage) {
this.callCount++;
super.notify(notiMessage);
}

}
42 changes: 42 additions & 0 deletions src/test/java/net/slipp/todo_list/CountableNotiManagerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package net.slipp.todo_list;

import java.util.Random;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.assertEquals;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { AppConfig.class } )
public class CountableNotiManagerTest {

private static final String TEST_STR = "Test";

@Autowired
private CountableNotiManager countableNotiManager;

@Test
public void CountableNotiManager의_정상_Count를_확인(){

countableNotiManager.notify(TEST_STR);

assertEquals(1, countableNotiManager.getCallCount());
}


@Test
public void CountableNotiManager의_랜덤으로_호출시_정상_Count를_확인(){

int maxCount = (int)Math.random() * 10;

for(int i = 0; i < maxCount; i++){
countableNotiManager.notify(TEST_STR);
}

assertEquals(maxCount, countableNotiManager.getCallCount());
}
}