Skip to content

Commit 16e630c

Browse files
committed
hardened json parsing + updated tests
1 parent dfc9b78 commit 16e630c

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed
76 KB
Binary file not shown.

core/src/androidTest/assets/product.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,10 @@
1010
"eans": [
1111
"0"
1212
],
13+
"codes": [
14+
{
15+
"code": "0"
16+
}
17+
],
1318
"productType": "default"
1419
}

core/src/androidTest/java/io/snabble/sdk/ProductDatabaseTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,4 +388,16 @@ public void testTransmissionCodeIsSameOnOldDbVersion() throws IOException, Snabb
388388

389389
Assert.assertEquals(product.getTransmissionCode(product.getScannableCodes()[0]), product.getScannableCodes()[0]);
390390
}
391+
392+
393+
@Test
394+
public void testTransmissionCode() throws IOException, Snabble.SnabbleException {
395+
setupSdkWithDb("demoDb_1_11.sqlite3");
396+
397+
ProductDatabase productDatabase = project.getProductDatabase();
398+
Product product = productDatabase.findBySku("48");
399+
Assert.assertNotNull(product);
400+
401+
Assert.assertEquals(product.getTransmissionCode(product.getScannableCodes()[0]), "00000" + product.getScannableCodes()[0]);
402+
}
391403
}

core/src/main/java/io/snabble/sdk/ProductApi.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ private Product toProduct(ApiProduct apiProduct, Product depositProduct, Product
385385

386386
if(apiProduct.codes != null) {
387387
for (ApiScannableCode apiScannableCode : apiProduct.codes) {
388-
builder.addTransmissionCode(apiScannableCode.code, apiScannableCode.transmissionCode);
388+
if(apiScannableCode.code != null && apiScannableCode.transmissionCode != null) {
389+
builder.addTransmissionCode(apiScannableCode.code, apiScannableCode.transmissionCode);
390+
}
389391
}
390392
}
391393

0 commit comments

Comments
 (0)