@Test
 public void handlesDifferentAttributeSeparators() throws Exception {
   mqttCommandPort.setTopic("test");
   int i = 0;
   for (String s : separators) {
     mqttCommandPort.setAttributeSeparator(s);
     receiveMqttMessage("On", "test/" + TEST_ITEM_NAME + s + ATTRIBUTE);
     i++;
     verify(testItem, times(i)).setAttributeValue(ATTRIBUTE, "On");
   }
 }
 @Test
 public void handlesBadAttributeSeparators() throws Exception {
   mqttCommandPort.setTopic("test");
   int i = 0;
   for (String s : badSeparators) {
     try {
       mqttCommandPort.setAttributeSeparator(s);
       assertThat(true, is(false));
     } catch (IllegalValueException e) {
       assertThat(e.getValue(), is(s));
     }
   }
 }
  @Test
  public void setsAttributeValue() throws Exception {
    mqttCommandPort.setTopic("test");
    receiveMqttMessage("On", "test/" + TEST_ITEM_NAME + ATTRIBUTE_SEPARATOR + ATTRIBUTE);

    verify(testItem).setAttributeValue(ATTRIBUTE, "On");
  }
  @Test
  public void callsCorrectAction() throws Exception {
    mqttCommandPort.setTopic("test");
    receiveMqttMessage("On", "test/" + TEST_ITEM_NAME);

    verify(testItem).callAction("On");
  }
  @Test
  public void findsCorrectHomeItemForActionWithThreeLevelTopic() throws Exception {
    mqttCommandPort.setTopic("test/more/levels");
    receiveMqttMessage("On", "test/more/levels/" + TEST_ITEM_NAME);

    verify(service).openInstance(TEST_ITEM_NAME);
  }
 private void receiveMqttMessage(String value, String topic) {
   Event event = new InternalEvent("Mqtt_Message");
   event.setAttribute("Mqtt.Topic", topic);
   event.setAttribute("Mqtt.Message", value);
   event.setAttribute("Direction", "In");
   mqttCommandPort.receiveEvent(event);
 }
 @Before
 public void setUp() throws Exception {
   mqttCommandPort = new MqttCommandPort();
   service = mock(HomeService.class);
   mqttCommandPort.activate(service);
   testItem = mock(HomeItemProxy.class);
   doReturn(testItem).when(service).openInstance(TEST_ITEM_NAME);
 }