Package com.cumulocity.model.control

Source Code of com.cumulocity.model.control.RelayTest

package com.cumulocity.model.control;

import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.svenson.JSONParser;

import c8y.Relay;
import c8y.Relay.RelayState;

public class RelayTest {

    private String relayRepresentationWithValidState = "{\"relayState\":\"OPEN\"}";

    private String relayRepresentationWithInvalidState = "{\"relayState\":\"MEH\"}";

    @Test
    public final void testThatTheRepresentationOfTheEnumerationSerializesCorrectlyIfStateIsValid() {
        Relay relay = new Relay();
        relay.setRelayState(RelayState.OPEN);
        Relay newRelay = JSONParser.defaultJSONParser().parse(Relay.class, relayRepresentationWithValidState);
        assertTrue(newRelay.getRelayState().equals(relay.getRelayState()));
    }

    @Test(expected = IllegalArgumentException.class)
    public final void testThatTheRepresentationOfTheEnumerationDoesNotSerializeCorrectlyIfStateIsInvalid() {
        JSONParser.defaultJSONParser().parse(Relay.class, relayRepresentationWithInvalidState);
        // IllegalArgumentException should be thrown.
    }

}
TOP

Related Classes of com.cumulocity.model.control.RelayTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.