### Question:
MBeanAttributeReadHandler extends ReadHandler { @Override public JsonValue getValueObject() throws JsonException { try { Object attribute = delegate .getMBeanAttribute(mbeanname, attributename); if (attribute == null) { return JsonValue.NULL; } TypeProcessor<?> processor = ProcessorFactory.getTypeProcessor(attribute); return processor.processObject(attribute); } catch (InstanceNotFoundException | ReflectionException | MalformedObjectNameException | MBeanException | AttributeNotFoundException ex) { super.setStatus(Response.Status.NOT_FOUND); return getTraceObject(ex); } } MBeanAttributeReadHandler(@Singleton MBeanServerDelegate delegate, 
            String mbeanname, String attributename); @Override JsonObject getRequestObject(); @Override JsonValue getValueObject();  }### Answer:
@Test public void getValueObject_String() throws Exception { MBeanAttributeReadHandler handler = new MBeanAttributeReadHandler(delegateMock, BEAN_NAME, BEAN_ATTRIBUTE); when(delegateMock.getMBeanAttribute(BEAN_NAME, BEAN_ATTRIBUTE)).thenReturn("Payara"); JsonValue value = handler.getValueObject(); assertThat(value.getValueType()).isEqualTo(JsonValue.ValueType.STRING); assertThat(((JsonString) value).getString()).isEqualTo("Payara"); }
@Test public void getValueObject_Long() throws Exception { MBeanAttributeReadHandler handler = new MBeanAttributeReadHandler(delegateMock, BEAN_NAME, BEAN_ATTRIBUTE); when(delegateMock.getMBeanAttribute(BEAN_NAME, BEAN_ATTRIBUTE)).thenReturn(123L); JsonValue value = handler.getValueObject(); assertThat(value.getValueType()).isEqualTo(JsonValue.ValueType.NUMBER); assertThat(((JsonNumber) value).longValue()).isEqualTo(123L); }
@Test public void getValueObject_Boolean() throws Exception { MBeanAttributeReadHandler handler = new MBeanAttributeReadHandler(delegateMock, BEAN_NAME, BEAN_ATTRIBUTE); when(delegateMock.getMBeanAttribute(BEAN_NAME, BEAN_ATTRIBUTE)).thenReturn(Boolean.TRUE); JsonValue value = handler.getValueObject(); assertThat(value).isEqualTo(JsonValue.TRUE); }
@Test public void getValueObject_Array() throws Exception { MBeanAttributeReadHandler handler = new MBeanAttributeReadHandler(delegateMock, BEAN_NAME, BEAN_ATTRIBUTE); when(delegateMock.getMBeanAttribute(BEAN_NAME, BEAN_ATTRIBUTE)).thenReturn(new Integer[]{1,2,3}); JsonValue value = handler.getValueObject(); assertThat(value.getValueType()).isEqualTo(JsonValue.ValueType.ARRAY); List<JsonNumber> data = ((JsonArray) value).getValuesAs(JsonNumber.class); assertThat(data.stream().map(JsonNumber::intValue)).containsExactly(1, 2, 3); }
@Test public void getValueObject_null() throws Exception { MBeanAttributeReadHandler handler = new MBeanAttributeReadHandler(delegateMock, BEAN_NAME, BEAN_ATTRIBUTE); when(delegateMock.getMBeanAttribute(BEAN_NAME, BEAN_ATTRIBUTE)).thenReturn(null); JsonValue value = handler.getValueObject(); System.out.println(value); }