Skip to content

Instantly share code, notes, and snippets.

@Romeh
Last active November 17, 2017 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Romeh/ffcd4263f55e7c464388d75263288473 to your computer and use it in GitHub Desktop.
Save Romeh/ffcd4263f55e7c464388d75263288473 to your computer and use it in GitHub Desktop.
@RunWith(MockitoJUnitRunner.class)
public class IgniteAlertsSoreTest {
@Mock
private Ignite ignite;
@Mock
Cache<String, List<AlertEntry>> cache;
@Mock
IgniteCache IgniteCache;
@InjectMocks
private IgniteAlertsStore igniteAlertsStore;
//simulate the needed behaviour for the mocked ignite cache
@Before
public void setUp() throws Exception {
when(ignite.getOrCreateCache(anyString())).thenReturn(IgniteCache);
List<AlertEntry> entries=new ArrayList<>();
entries.add(AlertEntry.builder().errorCode("errorCode").build());
when(IgniteCache.get(anyString())).thenReturn(entries);
}
@Test
public void getAllAlerts() throws Exception {
assertEquals(igniteAlertsStore.getAlertForServiceId("serviceId").get(0).getErrorCode(),"errorCode");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment