MicrochipPotentiometerDeviceController { public void setValue(final DeviceControllerChannel channel, final int value, final boolean nonVolatile) throws IOException { if (channel == null) { throw new RuntimeException("null-channel is not allowed. For devices " + "knowing just one wiper Channel.A is mandatory for " + "parameter 'channel'"); } if (value < 0) { throw new RuntimeException("only positive values are allowed! Got value '" + value + "' for writing to channel '" + channel.name() + "'"); } byte memAddr = nonVolatile ? channel.getNonVolatileMemoryAddress() : channel.getVolatileMemoryAddress(); write(memAddr, value); } MicrochipPotentiometerDeviceController(final I2CDevice i2cDevice); DeviceControllerDeviceStatus getDeviceStatus(); void increase(final DeviceControllerChannel channel, final int steps); void decrease(final DeviceControllerChannel channel, final int steps); int getValue(final DeviceControllerChannel channel, final boolean nonVolatile); void setValue(final DeviceControllerChannel channel, final int value,
			final boolean nonVolatile); DeviceControllerTerminalConfiguration getTerminalConfiguration(
			final DeviceControllerChannel channel); void setTerminalConfiguration(final DeviceControllerTerminalConfiguration config); void setWiperLock(final DeviceControllerChannel channel,
			final boolean locked); void setWriteProtection(final boolean enabled); @Override String toString(); @Override boolean equals(final Object obj); static final boolean VOLATILE_WIPER; static final boolean NONVOLATILE_WIPER; }
@Test public void testSetValue() throws IOException { try { controller.setValue(null, 1, true); fail("Got no RuntimeException on calling 'setValue(null, ...)'!"); } catch (RuntimeException e) { } try { controller.setValue(DeviceControllerChannel.A, -1, true); fail("Got no RuntimeException on calling 'setValue(...)' using a negative value!"); } catch (RuntimeException e) { } controller.setValue(DeviceControllerChannel.A, 0, false); verify(i2cDevice).write(new byte[] { (byte) 0b0000000, (byte) 0b00000000 }, 0, 2); verify(i2cDevice).write(any(byte[].class), anyInt(), anyInt()); reset(i2cDevice); controller.setValue(DeviceControllerChannel.B, 1, false); verify(i2cDevice).write(new byte[] { (byte) 0b0010000, (byte) 0b00000001 }, 0, 2); verify(i2cDevice).write(any(byte[].class), anyInt(), anyInt()); reset(i2cDevice); controller.setValue(DeviceControllerChannel.A, 255, true); verify(i2cDevice).write(new byte[] { (byte) 0b0100000, (byte) 0b11111111 }, 0, 2); verify(i2cDevice).write(any(byte[].class), anyInt(), anyInt()); reset(i2cDevice); controller.setValue(DeviceControllerChannel.B, 256, true); verify(i2cDevice).write(new byte[] { (byte) 0b0110001, (byte) 0b00000000 }, 0, 2); verify(i2cDevice).write(any(byte[].class), anyInt(), anyInt()); }