Skip to content

Commit b342a73

Browse files
committed
Cleanup
Signed-off-by: Alex Saveau <[email protected]> Cleanup and merge Signed-off-by: Alex Saveau <[email protected]> Cleanup Signed-off-by: Alex Saveau <[email protected]> Cleanup Signed-off-by: Alex Saveau <[email protected]>
1 parent 6be68d5 commit b342a73

File tree

7 files changed

+85
-82
lines changed

7 files changed

+85
-82
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
package com.firebase.ui.database;
22

33
public class Bean {
4-
private int number;
5-
private String text;
6-
private boolean bool;
4+
private int mNumber;
5+
private String mText;
6+
private boolean mBool;
77

88
public Bean() {
9+
// Needed for Firebase
910
}
1011

1112
public Bean(int number, String text, boolean bool) {
12-
this.number = number;
13-
this.text = text;
14-
this.bool = bool;
13+
mNumber = number;
14+
mText = text;
15+
mBool = bool;
1516
}
1617

1718
public Bean(int index) {
1819
this(index, "Text " + index, index % 2 == 0);
1920
}
2021

2122
public int getNumber() {
22-
return number;
23+
return mNumber;
2324
}
2425

2526
public String getText() {
26-
return text;
27+
return mText;
2728
}
2829

2930
public boolean isBool() {
30-
return bool;
31+
return mBool;
3132
}
3233
}

database/src/androidTest/java/com/firebase/ui/database/FirebaseArrayOfObjectsTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import static com.firebase.ui.database.TestUtils.getAppInstance;
3232
import static com.firebase.ui.database.TestUtils.getBean;
3333
import static com.firebase.ui.database.TestUtils.runAndWaitUntil;
34-
import static org.junit.Assert.assertEquals;
3534

3635
@RunWith(AndroidJUnit4.class)
3736
public class FirebaseArrayOfObjectsTest {
@@ -43,8 +42,10 @@ public class FirebaseArrayOfObjectsTest {
4342
@Before
4443
public void setUp() throws Exception {
4544
FirebaseApp app = getAppInstance(InstrumentationRegistry.getContext());
46-
mRef = FirebaseDatabase.getInstance(app).getReference()
47-
.child("firebasearray").child("objects");
45+
mRef = FirebaseDatabase.getInstance(app)
46+
.getReference()
47+
.child("firebasearray")
48+
.child("objects");
4849
mArray = new FirebaseArray(mRef);
4950
mRef.removeValue();
5051
runAndWaitUntil(mArray, new Runnable() {
@@ -64,18 +65,14 @@ public Boolean call() throws Exception {
6465

6566
@After
6667
public void tearDown() throws Exception {
67-
if (mRef != null) {
68-
mRef.getRoot().removeValue();
69-
}
70-
71-
if (mArray != null) {
72-
mArray.cleanup();
73-
}
68+
mArray.cleanup();
69+
mRef.getRoot().removeValue();
7470
}
7571

7672
@Test
7773
public void testPushIncreasesSize() throws Exception {
7874
runAndWaitUntil(mArray, new Runnable() {
75+
@Override
7976
public void run() {
8077
mRef.push().setValue(new Bean(4));
8178
}
@@ -90,6 +87,7 @@ public Boolean call() throws Exception {
9087
@Test
9188
public void testPushAppends() throws Exception {
9289
runAndWaitUntil(mArray, new Runnable() {
90+
@Override
9391
public void run() {
9492
mRef.push().setValue(new Bean(4), 4);
9593
}
@@ -104,10 +102,12 @@ public Boolean call() throws Exception {
104102
@Test
105103
public void testAddValueWithPriority() throws Exception {
106104
runAndWaitUntil(mArray, new Runnable() {
105+
@Override
107106
public void run() {
108107
mRef.push().setValue(new Bean(4), 0.5);
109108
}
110109
}, new Callable<Boolean>() {
110+
@Override
111111
public Boolean call() throws Exception {
112112
return mArray.getItem(3).getValue(Bean.class).getNumber() == 3 && mArray.getItem(0)
113113
.getValue(Bean.class)
@@ -119,10 +119,12 @@ public Boolean call() throws Exception {
119119
@Test
120120
public void testChangePriorities() throws Exception {
121121
runAndWaitUntil(mArray, new Runnable() {
122+
@Override
122123
public void run() {
123124
mArray.getItem(2).getRef().setPriority(0.5);
124125
}
125126
}, new Callable<Boolean>() {
127+
@Override
126128
public Boolean call() throws Exception {
127129
return getBean(mArray, 0).getNumber() == 3
128130
&& getBean(mArray, 1).getNumber() == 1

database/src/androidTest/java/com/firebase/ui/database/FirebaseArrayTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import static com.firebase.ui.database.TestUtils.getAppInstance;
3232
import static com.firebase.ui.database.TestUtils.isValuesEqual;
3333
import static com.firebase.ui.database.TestUtils.runAndWaitUntil;
34-
import static org.junit.Assert.assertEquals;
3534

3635
@RunWith(AndroidJUnit4.class)
3736
public class FirebaseArrayTest {
@@ -46,12 +45,14 @@ public void setUp() throws Exception {
4645
mArray = new FirebaseArray(mRef);
4746
mRef.removeValue();
4847
runAndWaitUntil(mArray, new Runnable() {
48+
@Override
4949
public void run() {
5050
for (int i = 1; i <= INITIAL_SIZE; i++) {
5151
mRef.push().setValue(i, i);
5252
}
5353
}
5454
}, new Callable<Boolean>() {
55+
@Override
5556
public Boolean call() throws Exception {
5657
return mArray.getCount() == INITIAL_SIZE;
5758
}
@@ -60,18 +61,14 @@ public Boolean call() throws Exception {
6061

6162
@After
6263
public void tearDown() throws Exception {
63-
if (mRef != null) {
64-
mRef.getRoot().removeValue();
65-
}
66-
67-
if (mArray != null) {
68-
mArray.cleanup();
69-
}
64+
mArray.cleanup();
65+
mRef.getRoot().removeValue();
7066
}
7167

7268
@Test
7369
public void testPushIncreasesSize() throws Exception {
7470
runAndWaitUntil(mArray, new Runnable() {
71+
@Override
7572
public void run() {
7673
mRef.push().setValue(4);
7774
}
@@ -86,6 +83,7 @@ public Boolean call() throws Exception {
8683
@Test
8784
public void testPushAppends() throws Exception {
8885
runAndWaitUntil(mArray, new Runnable() {
86+
@Override
8987
public void run() {
9088
mRef.push().setValue(4, 4);
9189
}
@@ -100,10 +98,12 @@ public Boolean call() throws Exception {
10098
@Test
10199
public void testAddValueWithPriority() throws Exception {
102100
runAndWaitUntil(mArray, new Runnable() {
101+
@Override
103102
public void run() {
104103
mRef.push().setValue(4, 0.5);
105104
}
106105
}, new Callable<Boolean>() {
106+
@Override
107107
public Boolean call() throws Exception {
108108
return mArray.getItem(3).getValue(Integer.class).equals(3)
109109
&& mArray.getItem(0).getValue(Integer.class).equals(4);
@@ -114,10 +114,12 @@ public Boolean call() throws Exception {
114114
@Test
115115
public void testChangePriorityBackToFront() throws Exception {
116116
runAndWaitUntil(mArray, new Runnable() {
117+
@Override
117118
public void run() {
118119
mArray.getItem(2).getRef().setPriority(0.5);
119120
}
120121
}, new Callable<Boolean>() {
122+
@Override
121123
public Boolean call() throws Exception {
122124
return isValuesEqual(mArray, new int[]{3, 1, 2});
123125
}
@@ -127,10 +129,12 @@ public Boolean call() throws Exception {
127129
@Test
128130
public void testChangePriorityFrontToBack() throws Exception {
129131
runAndWaitUntil(mArray, new Runnable() {
132+
@Override
130133
public void run() {
131134
mArray.getItem(0).getRef().setPriority(4);
132135
}
133136
}, new Callable<Boolean>() {
137+
@Override
134138
public Boolean call() throws Exception {
135139
return isValuesEqual(mArray, new int[]{2, 3, 1});
136140
}

database/src/androidTest/java/com/firebase/ui/database/FirebaseIndexArrayOfObjectsTest.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import static com.firebase.ui.database.TestUtils.getAppInstance;
3131
import static com.firebase.ui.database.TestUtils.getBean;
3232
import static com.firebase.ui.database.TestUtils.runAndWaitUntil;
33-
import static org.junit.Assert.assertEquals;
3433

3534
@RunWith(AndroidJUnit4.class)
3635
public class FirebaseIndexArrayOfObjectsTest {
@@ -55,7 +54,7 @@ public void setUp() throws Exception {
5554
@Override
5655
public void run() {
5756
for (int i = 1; i <= INITIAL_SIZE; i++) {
58-
pushValue(new Bean(i, "Text " + i, i % 2 == 0), i);
57+
TestUtils.pushValue(mKeyRef, mRef, new Bean(i, "Text " + i, i % 2 == 0), i);
5958
}
6059
}
6160
}, new Callable<Boolean>() {
@@ -68,20 +67,16 @@ public Boolean call() throws Exception {
6867

6968
@After
7069
public void tearDown() throws Exception {
71-
if (mRef != null) {
72-
mRef.getRoot().removeValue();
73-
}
74-
75-
if (mArray != null) {
76-
mArray.cleanup();
77-
}
70+
mArray.cleanup();
71+
mRef.getRoot().removeValue();
7872
}
7973

8074
@Test
8175
public void testPushIncreasesSize() throws Exception {
8276
runAndWaitUntil(mArray, new Runnable() {
77+
@Override
8378
public void run() {
84-
pushValue(new Bean(4), null);
79+
TestUtils.pushValue(mKeyRef, mRef, new Bean(4), null);
8580
}
8681
}, new Callable<Boolean>() {
8782
@Override
@@ -94,8 +89,9 @@ public Boolean call() throws Exception {
9489
@Test
9590
public void testPushAppends() throws Exception {
9691
runAndWaitUntil(mArray, new Runnable() {
92+
@Override
9793
public void run() {
98-
pushValue(new Bean(4), 4);
94+
TestUtils.pushValue(mKeyRef, mRef, new Bean(4), 4);
9995
}
10096
}, new Callable<Boolean>() {
10197
@Override
@@ -108,10 +104,12 @@ public Boolean call() throws Exception {
108104
@Test
109105
public void testAddValueWithPriority() throws Exception {
110106
runAndWaitUntil(mArray, new Runnable() {
107+
@Override
111108
public void run() {
112-
pushValue(new Bean(4), 0.5);
109+
TestUtils.pushValue(mKeyRef, mRef, new Bean(4), 0.5);
113110
}
114111
}, new Callable<Boolean>() {
112+
@Override
115113
public Boolean call() throws Exception {
116114
return mArray.getItem(3).getValue(Bean.class).getNumber() == 3 && mArray.getItem(0)
117115
.getValue(Bean.class)
@@ -123,10 +121,12 @@ public Boolean call() throws Exception {
123121
@Test
124122
public void testChangePriorities() throws Exception {
125123
runAndWaitUntil(mArray, new Runnable() {
124+
@Override
126125
public void run() {
127126
mKeyRef.child(mArray.getItem(2).getKey()).setPriority(0.5);
128127
}
129128
}, new Callable<Boolean>() {
129+
@Override
130130
public Boolean call() throws Exception {
131131
return getBean(mArray, 0).getNumber() == 3
132132
&& getBean(mArray, 1).getNumber() == 1
@@ -135,16 +135,4 @@ && getBean(mArray, 1).getNumber() == 1
135135
}
136136
});
137137
}
138-
139-
private void pushValue(Object value, Object priority) {
140-
String key = mKeyRef.push().getKey();
141-
142-
if (priority != null) {
143-
mKeyRef.child(key).setValue(true, priority);
144-
mRef.child(key).setValue(value, priority);
145-
} else {
146-
mKeyRef.child(key).setValue(true);
147-
mRef.child(key).setValue(value);
148-
}
149-
}
150138
}

database/src/androidTest/java/com/firebase/ui/database/FirebaseIndexArrayTest.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void setUp() throws Exception {
5454
@Override
5555
public void run() {
5656
for (int i = 1; i <= INITIAL_SIZE; i++) {
57-
pushValue(i, i);
57+
TestUtils.pushValue(mKeyRef, mRef, i, i);
5858
}
5959
}
6060
}, new Callable<Boolean>() {
@@ -67,20 +67,16 @@ public Boolean call() throws Exception {
6767

6868
@After
6969
public void tearDown() throws Exception {
70-
if (mRef != null) {
71-
mRef.getRoot().removeValue();
72-
}
73-
74-
if (mArray != null) {
75-
mArray.cleanup();
76-
}
70+
mArray.cleanup();
71+
mRef.getRoot().removeValue();
7772
}
7873

7974
@Test
8075
public void testPushIncreasesSize() throws Exception {
8176
runAndWaitUntil(mArray, new Runnable() {
77+
@Override
8278
public void run() {
83-
pushValue(4, null);
79+
TestUtils.pushValue(mKeyRef, mRef, 4, null);
8480
}
8581
}, new Callable<Boolean>() {
8682
@Override
@@ -93,8 +89,9 @@ public Boolean call() throws Exception {
9389
@Test
9490
public void testPushAppends() throws Exception {
9591
runAndWaitUntil(mArray, new Runnable() {
92+
@Override
9693
public void run() {
97-
pushValue(4, 4);
94+
TestUtils.pushValue(mKeyRef, mRef, 4, 4);
9895
}
9996
}, new Callable<Boolean>() {
10097
@Override
@@ -107,10 +104,12 @@ public Boolean call() throws Exception {
107104
@Test
108105
public void testAddValueWithPriority() throws Exception {
109106
runAndWaitUntil(mArray, new Runnable() {
107+
@Override
110108
public void run() {
111-
pushValue(4, 0.5);
109+
TestUtils.pushValue(mKeyRef, mRef, 4, 0.5);
112110
}
113111
}, new Callable<Boolean>() {
112+
@Override
114113
public Boolean call() throws Exception {
115114
return mArray.getItem(3).getValue(Integer.class).equals(3)
116115
&& mArray.getItem(0).getValue(Integer.class).equals(4);
@@ -121,25 +120,15 @@ public Boolean call() throws Exception {
121120
@Test
122121
public void testChangePriorities() throws Exception {
123122
runAndWaitUntil(mArray, new Runnable() {
123+
@Override
124124
public void run() {
125125
mKeyRef.child(mArray.getItem(2).getKey()).setPriority(0.5);
126126
}
127127
}, new Callable<Boolean>() {
128+
@Override
128129
public Boolean call() throws Exception {
129130
return isValuesEqual(mArray, new int[]{3, 1, 2});
130131
}
131132
});
132133
}
133-
134-
private void pushValue(Object value, Object priority) {
135-
String key = mKeyRef.push().getKey();
136-
137-
if (priority != null) {
138-
mKeyRef.child(key).setValue(true, priority);
139-
mRef.child(key).setValue(value, priority);
140-
} else {
141-
mKeyRef.child(key).setValue(true);
142-
mRef.child(key).setValue(value);
143-
}
144-
}
145134
}

0 commit comments

Comments
 (0)