Skip to content

Commit 2d7952d

Browse files
Unit test fixes
1 parent 818271f commit 2d7952d

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

firebase-database/src/main/java/com/google/firebase/database/core/utilities/encoding/CustomClassMapper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,9 @@ private static <T> Object serialize(T o) {
122122
return o;
123123
} else {
124124
throw new DatabaseException(
125-
o.getClass().getSimpleName()
126-
+ " is not supported, please use an int, long, float or double");
125+
String.format(
126+
"Numbers of type %s are not supported, please use an int, long, float or double",
127+
o.getClass().getSimpleName()));
127128
}
128129
} else if (o instanceof String) {
129130
return o;
@@ -279,7 +280,7 @@ private static <T> T deserializeToPrimitive(Object o, Class<T> clazz) {
279280
return (T) (Float) convertDouble(o).floatValue();
280281
} else {
281282
throw new DatabaseException(
282-
String.format("Deserializing to %s is not supported", clazz.getSimpleName()));
283+
String.format("Deserializing values to %s is not supported", clazz.getSimpleName()));
283284
}
284285
}
285286

firebase-firestore/src/main/java/com/google/firebase/firestore/util/CustomClassMapper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private static <T> Object serialize(T o, ErrorPath path) {
119119
throw serializeError(
120120
path,
121121
String.format(
122-
"%s is not supported, please use an int, long, float or double",
122+
"Numbers of type %s are not supported, please use an int, long, float or double",
123123
o.getClass().getSimpleName()));
124124
}
125125
} else if (o instanceof String) {
@@ -314,7 +314,8 @@ private static <T> T deserializeToPrimitive(Object o, Class<T> clazz, ErrorPath
314314
return (T) (Float) convertDouble(o, path).floatValue();
315315
} else {
316316
throw deserializeError(
317-
path, String.format("Deserializing to %s is not supported", clazz.getSimpleName()));
317+
path,
318+
String.format("Deserializing values to %s is not supported", clazz.getSimpleName()));
318319
}
319320
}
320321

firebase-firestore/src/test/java/com/google/firebase/firestore/util/MapperTest.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,9 @@ public void serializeBooleanBean() {
14421442
public void serializeFloatBean() {
14431443
FloatBean bean = new FloatBean();
14441444
bean.value = 0.5f;
1445-
assertJson("{'value': 0.5}", serialize(bean));
1445+
1446+
// We don't use assertJson as it converts all floating point numbers to Double.
1447+
assertEquals(map("value", 0.5f), serialize(bean));
14461448
}
14471449

14481450
@Test
@@ -1696,7 +1698,7 @@ public void shortsCantBeSerialized() {
16961698
ShortBean bean = new ShortBean();
16971699
bean.value = 1;
16981700
assertExceptionContains(
1699-
"Shorts are not supported, please use int or long (found in field 'value')",
1701+
"Numbers of type Short are not supported, please use an int, long, float or double (found in field 'value')",
17001702
() -> serialize(bean));
17011703
}
17021704

@@ -1705,7 +1707,7 @@ public void bytesCantBeSerialized() {
17051707
ByteBean bean = new ByteBean();
17061708
bean.value = 1;
17071709
assertExceptionContains(
1708-
"Bytes are not supported, please use int or long (found in field 'value')",
1710+
"Numbers of type Byte are not supported, please use an int, long, float or double (found in field 'value')",
17091711
() -> serialize(bean));
17101712
}
17111713

@@ -1714,7 +1716,7 @@ public void charsCantBeSerialized() {
17141716
CharBean bean = new CharBean();
17151717
bean.value = 1;
17161718
assertExceptionContains(
1717-
"Characters are not supported, please use Strings. (found in field 'value')",
1719+
"Characters are not supported, please use Strings (found in field 'value')",
17181720
() -> serialize(bean));
17191721
}
17201722

@@ -1741,21 +1743,21 @@ public void objectArraysCantBeSerialized() {
17411743
@Test
17421744
public void shortsCantBeDeserialized() {
17431745
assertExceptionContains(
1744-
"Deserializing to shorts is not supported (found in field 'value')",
1746+
"Deserializing values to short is not supported (found in field 'value')",
17451747
() -> deserialize("{'value': 1}", ShortBean.class));
17461748
}
17471749

17481750
@Test
17491751
public void bytesCantBeDeserialized() {
17501752
assertExceptionContains(
1751-
"Deserializing to bytes is not supported (found in field 'value')",
1753+
"Deserializing values to byte is not supported (found in field 'value')",
17521754
() -> deserialize("{'value': 1}", ByteBean.class));
17531755
}
17541756

17551757
@Test
17561758
public void charsCantBeDeserialized() {
17571759
assertExceptionContains(
1758-
"Deserializing to chars is not supported (found in field 'value')",
1760+
"Deserializing values to char is not supported (found in field 'value')",
17591761
() -> deserialize("{'value': '1'}", CharBean.class));
17601762
}
17611763

@@ -1862,21 +1864,21 @@ public void passingInMapTopLevelThrows() {
18621864
@Test
18631865
public void passingInCharacterTopLevelThrows() {
18641866
assertExceptionContains(
1865-
"Deserializing to chars is not supported",
1867+
"Deserializing values to Character is not supported",
18661868
() -> CustomClassMapper.convertToCustomClass('1', Character.class));
18671869
}
18681870

18691871
@Test
18701872
public void passingInShortTopLevelThrows() {
18711873
assertExceptionContains(
1872-
"Deserializing to shorts is not supported",
1874+
"Deserializing values to Short is not supported",
18731875
() -> CustomClassMapper.convertToCustomClass(1, Short.class));
18741876
}
18751877

18761878
@Test
18771879
public void passingInByteTopLevelThrows() {
18781880
assertExceptionContains(
1879-
"Deserializing to bytes is not supported",
1881+
"Deserializing values to Byte is not supported",
18801882
() -> CustomClassMapper.convertToCustomClass(1, Byte.class));
18811883
}
18821884

@@ -2220,8 +2222,8 @@ public void serializationFailureIncludesPath() {
22202222
fail("should have thrown");
22212223
} catch (RuntimeException e) {
22222224
assertEquals(
2223-
"Could not serialize object. Shorts are not supported, please use int or "
2224-
+ "long (found in field 'value.inner.value.short')",
2225+
"Could not serialize object. Numbers of type Short are not supported, please use an int, "
2226+
+ "long, float or double (found in field 'value.inner.value.short')",
22252227
e.getMessage());
22262228
}
22272229
}
@@ -2235,7 +2237,7 @@ public void deserializationFailureIncludesPath() {
22352237
fail("should have thrown");
22362238
} catch (RuntimeException e) {
22372239
assertEquals(
2238-
"Could not deserialize object. Deserializing to shorts is not supported "
2240+
"Could not deserialize object. Deserializing values to short is not supported "
22392241
+ "(found in field 'value')",
22402242
e.getMessage());
22412243
}

0 commit comments

Comments
 (0)