@Test public void updateDeviceEntry() { fakeReceiver.emitSingleCorrectMessage(); fakeReceiver.emitSingleCorrectMessageDifferentServices(); assertSame("Correct message not in cache", parser.getCache().size(), 1); assertSame("Correct message not in cache", parser.getCache().lastAnnounceSize(), 1); assertNull("Original message still in cache", parser.getCache().get(CORRECT_MESSAGE)); assertNotNull( "New message not in cache", parser.getCache().get(CORRECT_MESSAGE_DIFFERENT_SERVICES)); }
@Test public void addDeviceToCacheTest() { fakeReceiver.emitSingleCorrectMessage(); assertSame("Entries in cache != 1", parser.getCache().size(), 1); assertSame("Paths in cache != 1", parser.getCache().lastAnnounceSize(), 1); assertNotNull("JSON message not in cache", parser.getCache().get(CORRECT_MESSAGE)); fakeReceiver.emitSingleCorrectMessageDifferentDevice(); assertSame("Entries in cache != 2", parser.getCache().size(), 2); assertSame("Paths in cache != 2", parser.getCache().lastAnnounceSize(), 2); assertNotNull("JSON message not in cache", parser.getCache().get(CORRECT_MESSAGE)); assertNotNull( "JSON message not in cache", parser.getCache().get(CORRECT_MESSAGE_DIFFERENT_DEVICE)); }
@Test public void dontAddTwiceTest() { fakeReceiver.emitSingleCorrectMessage(); fakeReceiver.emitSingleCorrectMessage(); assertSame("Message was added more than once", parser.getCache().size(), 1); assertSame("Message was added more than once", parser.getCache().lastAnnounceSize(), 1); }
@Test public void getFromCacheTest() { fakeReceiver.emitSingleCorrectMessage(); assertNotNull("Correct message not in cache", parser.getCache().get(CORRECT_MESSAGE)); }
@Before public void setUp() { this.fakeReceiver = new FakeMessageReceiver(); this.parser = new AnnounceDeserializer(); fakeReceiver.addObserver(parser); }