GetConfigurationObjectServiceDsmr4 extends GetConfigurationObjectService { @Override ConfigurationObjectDto getConfigurationObject(final GetResult result) throws ProtocolAdapterException { final DataObject resultData = result.getResultData(); if (resultData == null || !resultData.isComplex()) { final String message = String.format("Expected ConfigurationObject ResultData as Complex, but got: %s", resultData); LOGGER.warn(message); throw new ProtocolAdapterException(message); } return this.getConfigurationObject(resultData); } GetConfigurationObjectServiceDsmr4(final DlmsHelper dlmsHelper); @Override boolean handles(final Protocol protocol);  }
@Test public void getConfigurationObjectResultDataNull() throws ProtocolAdapterException { when(this.getResult.getResultData()).thenReturn(null); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.instance.getConfigurationObject(this.getResult); }); }
@Test public void getConfigurationObjectResultDataNotComplex() throws ProtocolAdapterException { final DataObject nonComplex = mock(DataObject.class); when(nonComplex.isComplex()).thenReturn(false); when(this.getResult.getResultData()).thenReturn(nonComplex); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.instance.getConfigurationObject(this.getResult); }); }
@Test public void getConfigurationObjectElementsNull() throws ProtocolAdapterException { final DataObject structure = mock(DataObject.class); when(structure.isComplex()).thenReturn(true); when(this.getResult.getResultData()).thenReturn(structure); final List<DataObject> elements = null; when(structure.getValue()).thenReturn(elements); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.instance.getConfigurationObject(this.getResult); }); }
@Test public void getConfigurationObjectElementsSizeNotTwo() throws ProtocolAdapterException { final DataObject structure = mock(DataObject.class); when(structure.isComplex()).thenReturn(true); when(this.getResult.getResultData()).thenReturn(structure); final List<DataObject> elements = new ArrayList<>(); when(structure.getValue()).thenReturn(elements); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.instance.getConfigurationObject(this.getResult); }); }
@Test public void getConfigurationObjectGprsModeNull() throws ProtocolAdapterException { final DataObject structure = mock(DataObject.class); when(structure.isComplex()).thenReturn(true); when(this.getResult.getResultData()).thenReturn(structure); final List<DataObject> elements = new ArrayList<>(); elements.add(null); elements.add(null); when(structure.getValue()).thenReturn(elements); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.instance.getConfigurationObject(this.getResult); }); }
@Test public void getConfigurationObjectGprsModeNotNumber() throws ProtocolAdapterException { final DataObject structure = mock(DataObject.class); when(structure.isComplex()).thenReturn(true); when(this.getResult.getResultData()).thenReturn(structure); final List<DataObject> elements = new ArrayList<>(); final DataObject gprsMode = mock(DataObject.class); when(gprsMode.isNumber()).thenReturn(false); elements.add(gprsMode); elements.add(null); when(structure.getValue()).thenReturn(elements); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.instance.getConfigurationObject(this.getResult); }); }
@Test public void getConfigurationObjectFlagsNull() throws ProtocolAdapterException { final DataObject structure = mock(DataObject.class); when(structure.isComplex()).thenReturn(true); when(this.getResult.getResultData()).thenReturn(structure); final List<DataObject> elements = new ArrayList<>(); final DataObject gprsMode = mock(DataObject.class); when(gprsMode.isNumber()).thenReturn(true); when(gprsMode.getValue()).thenReturn(42); elements.add(gprsMode); elements.add(null); when(structure.getValue()).thenReturn(elements); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.instance.getConfigurationObject(this.getResult); }); }
@Test public void getConfigurationObjectFlagsNotBitString() throws ProtocolAdapterException { final DataObject structure = mock(DataObject.class); when(structure.isComplex()).thenReturn(true); when(this.getResult.getResultData()).thenReturn(structure); final List<DataObject> elements = new ArrayList<>(); final DataObject gprsMode = mock(DataObject.class); when(gprsMode.isNumber()).thenReturn(true); when(gprsMode.getValue()).thenReturn(42); elements.add(gprsMode); final DataObject flags = mock(DataObject.class); when(flags.isBitString()).thenReturn(false); elements.add(flags); when(structure.getValue()).thenReturn(elements); assertThatExceptionOfType(ProtocolAdapterException.class).isThrownBy(() -> { this.instance.getConfigurationObject(this.getResult); }); }