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
94
|
package com.cyngn.audiofx;
import android.os.Parcel;
import android.support.test.runner.AndroidJUnit4;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import com.cyngn.audiofx.Preset;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Created by roman on 9/29/15.
*/
@RunWith(AndroidJUnit4.class)
public class PresetParcelTests {
private Preset.PermCustomPreset permPreset;
private Preset.PermCustomPreset permPresetCopy;
private Preset.CustomPreset customPreset;
@Before
public void setUp() throws Exception {
permPreset = new Preset.PermCustomPreset("test perm preset", new float[]{10, 50, 20, 30, 10000});
permPresetCopy = new Preset.PermCustomPreset("test perm preset", new float[]{10, 50, 20, 30, 10000});
customPreset = new Preset.CustomPreset("test custom preset", new float[]{10, 50, 20, 30, 10000}, false);
}
@Test
public void testPresetsEqual() {
assertNotEquals(permPreset, customPreset);
assertEquals(permPreset, permPresetCopy);
}
@Test
public void testPresetsFromString() {
final String permPresetTest = permPreset.toString();
final Preset.PermCustomPreset fromString = Preset.PermCustomPreset.fromString(permPresetTest);
assertEquals(permPreset, fromString);
}
@Test
public void testPermPresetParcelable() {
Parcel parcel = Parcel.obtain();
// write the parcel
permPreset.writeToParcel(parcel, 0);
// reset position for reading
parcel.setDataPosition(0);
// reconstruct object
final Preset.PermCustomPreset fromParcel = Preset.PermCustomPreset.CREATOR.createFromParcel(parcel);
assertNotNull(fromParcel);
assertEquals(permPreset.getName(), fromParcel.getName());
assertPresetLevels(permPreset, fromParcel);
assertEquals(permPreset, fromParcel);
}
@Test
public void testCustomPresetParcelable() {
Parcel parcel = Parcel.obtain();
// write the parcel
customPreset.writeToParcel(parcel, 0);
// reset position for reading
parcel.setDataPosition(0);
// reconstruct object
final Preset.CustomPreset fromParcel = Preset.CustomPreset.CREATOR.createFromParcel(parcel);
assertNotNull(fromParcel);
assertEquals(customPreset.getName(), fromParcel.getName());
assertPresetLevels(customPreset, fromParcel);
assertEquals(customPreset.isLocked(), fromParcel.isLocked());
assertEquals(customPreset, fromParcel);
}
private void assertPresetLevels(Preset p1, Preset p2) {
for(int i = 0; i < p1.getLevels().length; i++) {
assertEquals(p1.getLevels()[i], p2.getLevels()[i], 0);
}
}
}
|