Skip to content

Instantly share code, notes, and snippets.

@Romeh
Last active Nov 17, 2017
Embed
What would you like to do?
@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