### Question:
JmsMockLocator { Optional<JmsMock> getJmsMockByConnectionFactory(ConnectionFactory connectionFactory) { return jmsMocks .stream() .filter(jmsMock -> jmsMock.connectionFactory == connectionFactory) .findFirst(); } JmsMockLocator(Set<JmsMock> jmsMocks);   }### Answer:
@Test void getJmsMockByConnectionFactory_returns_matching_object() { ConnectionFactory connectionFactory = mock(ConnectionFactory.class); ConnectionFactory connectionFactory2 = mock(ConnectionFactory.class); ConnectionFactory connectionFactory3 = mock(ConnectionFactory.class); JmsMock jmsMock = new JmsMock(connectionFactory, null); JmsMock jmsMock2 = new JmsMock(connectionFactory2, null); assertThat(connectionFactory == connectionFactory2).isFalse(); assertThat(jmsMock == jmsMock2).isFalse(); Set<JmsMock> jmsMocks = new HashSet<>(); jmsMocks.add(jmsMock); jmsMocks.add(jmsMock2); JmsMockLocator jmsMockLocator = new JmsMockLocator(jmsMocks); assertThat(jmsMockLocator.getJmsMockByConnectionFactory(connectionFactory)).contains(jmsMock); assertThat(jmsMockLocator.getJmsMockByConnectionFactory(connectionFactory2)).contains(jmsMock2); assertThat(jmsMockLocator.getJmsMockByConnectionFactory(connectionFactory3)).isEmpty(); }