ProtocolRequestMessageSender implements ProtocolRequestService { protected String getMessageGroupId(final String deviceIdentification) { return String.valueOf(Math.abs(deviceIdentification.hashCode() % this.messageGroupCacheSize)); }  @Override boolean isSupported(final ProtocolInfo protocolInfo); @Override void send(final ProtocolRequestMessage message, final ProtocolInfo protocolInfo);  }
@Test public void testMessageGroupIdShouldBeBetween0AndCacheSize() { for (int i = 0; i < 10000; i++) { final String uuid = UUID.randomUUID().toString(); final String messageGroupId = this.messageSender.getMessageGroupId(uuid); final int actual = Integer.valueOf(messageGroupId); assertThat(actual >= 0 && actual < this.messageGroupCacheSize) .as("Message group id should be between 0 and cache size " + this.messageGroupCacheSize).isTrue(); } }
@Test public void testMmessageGroupIdShouldBeSameForSameDevice() { final String deviceId = "test-device-001"; final Set<String> groupIds = new HashSet<>(); for (int i = 0; i < 100; i++) { groupIds.add(this.messageSender.getMessageGroupId(deviceId)); } final int actual = groupIds.size(); assertThat(actual == 1).as("Message group id should be the same for same device").isTrue(); }
@Test public void testNumberOfMessageGroupsShouldNotExceedCacheSize() { final Set<String> groupIds = new HashSet<>(); for (int i = 0; i < 10000; i++) { final String uuid = UUID.randomUUID().toString(); groupIds.add(this.messageSender.getMessageGroupId(uuid)); } final int actual = groupIds.size(); assertThat(actual <= this.messageGroupCacheSize) .as("Number of message groups should not exceed cache size " + this.messageGroupCacheSize).isTrue(); }
@Test public void numberOfMessageGroupsShouldNotExceedCacheSize() { final Set<String> groupIds = new HashSet<>(); for (int i = 0; i < 10000; i++) { final String uuid = UUID.randomUUID().toString(); groupIds.add(this.messageSender.getMessageGroupId(uuid)); } final int actual = groupIds.size(); assertTrue("Number of message groups should not exceed cache size " + this.messageGroupCacheSize, actual <= this.messageGroupCacheSize); }
@Test public void messageGroupIdShouldBeSameForSameDevice() { final String deviceId = "test-device-001"; final Set<String> groupIds = new HashSet<>(); for (int i = 0; i < 100; i++) { groupIds.add(this.messageSender.getMessageGroupId(deviceId)); } final int actual = groupIds.size(); assertTrue("Message group id should be the same for same device", actual == 1); }
@Test public void messageGroupIdShouldBeBetween0AndCacheSize() { for (int i = 0; i < 10000; i++) { final String uuid = UUID.randomUUID().toString(); final String messageGroupId = this.messageSender.getMessageGroupId(uuid); final int actual = Integer.valueOf(messageGroupId); assertTrue("Message group id should be between 0 and cache size " + this.messageGroupCacheSize, actual >= 0 && actual < this.messageGroupCacheSize); } }