Event { @Override public String toString() { try { BeanInfo beanInfo = Introspector.getBeanInfo(this.getClass()); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); StringBuilder builder = new StringBuilder(); builder.append("Event Properties =>"); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String name = propertyDescriptor.getName(); Object invoke = propertyDescriptor.getReadMethod().invoke(this); builder.append(" " + name + ":" + invoke + ";"); } return builder.toString(); } catch (IntrospectionException e) { return returnSimpleEventString(); } catch (IllegalArgumentException e) { return returnSimpleEventString(); } catch (IllegalAccessException e) { return returnSimpleEventString(); } catch (InvocationTargetException e) { return returnSimpleEventString(); } } Event();  Event(String name);  Event(Long processId);  Event(String name, Long processId); String getName(); void setName(String name); Long getProcessId(); void setProcessId(Long processId); String getOrigin(); void setOrigin(String origin); @Override String toString();  }
@Test public void testToString_shouldReturnCorrectString() throws Exception { Event event = new TestEvent("test"); String eventString = event.toString(); assertThat(eventString, containsString("class:" + event.getClass())); assertThat(eventString, containsString("int:5;")); assertThat(eventString, containsString("name:test")); }