Skip to content

Instantly share code, notes, and snippets.

@chbaranowski
Last active November 27, 2015 06:46
Show Gist options
  • Save chbaranowski/ace25052bf810ed81874 to your computer and use it in GitHub Desktop.
Save chbaranowski/ace25052bf810ed81874 to your computer and use it in GitHub Desktop.
KeyWordAnalyzerTest
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