1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
package com.smartdevicelink.test.rpc.datatypes;
import com.smartdevicelink.proxy.rpc.FuelRange;
import com.smartdevicelink.proxy.rpc.enums.CapacityUnit;
import com.smartdevicelink.proxy.rpc.enums.ComponentVolumeStatus;
import com.smartdevicelink.proxy.rpc.enums.FuelType;
import com.smartdevicelink.test.JsonUtils;
import com.smartdevicelink.test.TestValues;
import junit.framework.TestCase;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Iterator;
/**
* This is a unit test class for the SmartDeviceLink library project class :
* {@link com.smartdevicelink.proxy.rpc.FuelRange}
*/
public class FuelRangeTests extends TestCase{
private FuelRange msg;
@Override
public void setUp(){
msg = new FuelRange();
msg.setType(TestValues.GENERAL_FUELTYPE);
msg.setRange(TestValues.GENERAL_FLOAT);
msg.setLevel(TestValues.GENERAL_FLOAT);
msg.setLevelState(TestValues.GENERAL_COMPONENTVOLUMESTATUS);
msg.setCapacity(TestValues.GENERAL_FLOAT);
msg.setCapacityUnit(TestValues.GENERAL_CAPACITYUNIT);
}
/**
* Tests the expected values of the RPC message.
*/
public void testRpcValues () {
// Test Values
FuelType fuelType = msg.getType();
float range = msg.getRange();
float level = msg.getLevel();
ComponentVolumeStatus levelState = msg.getLevelState();
CapacityUnit capacityUnit = msg.getCapacityUnit();
float capacity = msg.getCapacity();
// Valid Tests
assertEquals(TestValues.MATCH, TestValues.GENERAL_FLOAT, range);
assertEquals(TestValues.MATCH, TestValues.GENERAL_FUELTYPE, fuelType);
assertEquals(TestValues.MATCH, TestValues.GENERAL_FLOAT, level);
assertEquals(TestValues.MATCH, TestValues.GENERAL_COMPONENTVOLUMESTATUS, levelState);
assertEquals(TestValues.MATCH, TestValues.GENERAL_CAPACITYUNIT, capacityUnit);
assertEquals(TestValues.MATCH, TestValues.GENERAL_FLOAT, capacity);
// Invalid/Null Tests
FuelRange msg = new FuelRange();
assertNotNull(TestValues.NOT_NULL, msg);
assertNull(TestValues.NULL, msg.getType());
assertNull(TestValues.NULL, msg.getRange());
assertNull(TestValues.NULL, msg.getLevel());
assertNull(TestValues.NULL, msg.getLevelState());
assertNull(TestValues.NULL, msg.getCapacityUnit());
assertNull(TestValues.NULL, msg.getCapacity());
}
public void testJson(){
JSONObject reference = new JSONObject();
try{
reference.put(FuelRange.KEY_TYPE, TestValues.GENERAL_FUELTYPE);
reference.put(FuelRange.KEY_RANGE, (Float) TestValues.GENERAL_FLOAT);
reference.put(FuelRange.KEY_LEVEL, TestValues.GENERAL_FLOAT);
reference.put(FuelRange.KEY_LEVEL_STATE, TestValues.GENERAL_COMPONENTVOLUMESTATUS);
reference.put(FuelRange.KEY_CAPACITY, TestValues.GENERAL_FLOAT);
reference.put(FuelRange.KEY_CAPACITY_UNIT, TestValues.GENERAL_CAPACITYUNIT);
JSONObject underTest = msg.serializeJSON();
assertEquals(TestValues.MATCH, reference.length(), underTest.length());
Iterator<?> iterator = reference.keys();
while(iterator.hasNext()) {
String key = (String) iterator.next();
assertEquals(TestValues.MATCH, JsonUtils.readObjectFromJsonObject(reference, key), JsonUtils.readObjectFromJsonObject(underTest, key));
}
}catch(JSONException e){
fail(TestValues.JSON_FAIL);
}
}
}
|