### Question:
Transformers { static void addOnOffAttrs(Model m, ImmutableMap.Builder<String, Object> attrs, Map<String, Object> params) { if(params == null) { params = ImmutableMap.of(); } assertCapability(m, SwitchCapability.NAMESPACE); Boolean on = (Boolean) params.get(Commands.OnOff.arg_on); if(on == null) { throw new ErrorEventException(Constants.Error.VALUE_OUT_OF_RANGE, Commands.OnOff.arg_on + " must be true or false"); } String newState = on ? SwitchCapability.STATE_ON : SwitchCapability.STATE_OFF; if(!Objects.equals(SwitchModel.getState(m), newState)) { attrs.put(SwitchCapability.ATTR_STATE, newState); } } private  Transformers(); static Optional<GoogleDevice> modelToDevice(Model m, boolean whitelisted, @Nullable ProductCatalogEntry pm, boolean reportStateEnabled); static Map<String,Object> modelToStateMap(Model m, boolean hubOffline, boolean whitelisted, @Nullable ProductCatalogEntry pm); static Optional<MessageBody> commandToMessageBody(Model m, boolean hubOffline, String command, Map<String, Object> params, boolean whitelisted, @Nullable ProductCatalogEntry pm); static PlatformMessage requestToMessage(Request req, UUID placeId, String population, int ttl); static Response messageToResponse(PlatformMessage msg); static final Gson GSON; static final String PRODUCT_ID; static final String TYPE_HINT; }### Answer:
@Test public void testAddOnOffAttrs() { ImmutableMap.Builder<String,Object> builder = ImmutableMap.builder(); try { Transformers.addOnOffAttrs(allCaps, builder, null); } catch(Throwable t) { assertErrorEvent(t, Constants.Error.VALUE_OUT_OF_RANGE); } try { Transformers.addOnOffAttrs(allCaps, builder, ImmutableMap.of()); } catch(Throwable t) { assertErrorEvent(t, Constants.Error.VALUE_OUT_OF_RANGE); } try { Model noSwitch = ModelFixtures.buildDeviceAttributes(DimmerCapability.NAMESPACE, ColorCapability.NAMESPACE, ColorTemperatureCapability.NAMESPACE) .toModel(); Transformers.addOnOffAttrs(noSwitch, builder, ImmutableMap.of(Constants.States.OnOff.ON, true)); } catch(Throwable t) { assertErrorEvent(t, Constants.Error.NOT_SUPPORTED); } Transformers.addOnOffAttrs(allCaps, builder, ImmutableMap.of(Constants.States.OnOff.ON, true)); assertEquals(ImmutableMap.of(SwitchCapability.ATTR_STATE, SwitchCapability.STATE_ON), builder.build()); }