Last active
November 27, 2015 06:46
-
-
Save chbaranowski/ace25052bf810ed81874 to your computer and use it in GitHub Desktop.
KeyWordAnalyzerTest
This file contains hidden or 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
import static org.mockito.Mockito.*; | |
import org.junit.Before; | |
import org.junit.Test; | |
import org.mockito.Mock; | |
import org.mockito.MockitoAnnotations; | |
public class KeyWordAnalyzerTest { | |
public static class SampleData { | |
public String param1; | |
public String param2; | |
} | |
KeyWordAnalyzer sut; | |
@Mock | |
KeyWordRepository mockKeyWordRepository; | |
SampleData data; | |
@Before | |
public void setup() throws Exception { | |
// setup mock object | |
MockitoAnnotations.initMocks(this); | |
// create sut and install test double | |
sut = new KeyWordAnalyzer(mockKeyWordRepository); | |
// setup sample object | |
data = new SampleData(); | |
data.param1 = "Sample Text XYZ"; | |
data.param2 = "Sample TOPIC 1234"; | |
} | |
@Test | |
public void reportObjectWithRelevantContent() throws Exception { | |
when(mockKeyWordRepository.findRelevantKeyWords(anyInt())) | |
.thenReturn(new String []{"Bomb", "TOPIC"}); | |
sut.analyze(data); | |
verify(mockKeyWordRepository).reportObject(data); | |
} | |
@Test | |
public void doNotReportObjectsWithIrrelevantContent() throws Exception { | |
when(mockKeyWordRepository.findRelevantKeyWords(anyInt())) | |
.thenReturn(new String []{"Bomb"}); | |
sut.analyze(data); | |
verify(mockKeyWordRepository, never()).reportObject(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment