-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added proper coverage for event builders
- Loading branch information
Showing
28 changed files
with
1,046 additions
and
517 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...cker/src/androidTest/java/com/snowplowanalytics/snowplow/tracker/DevicePlatformsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2015 Snowplow Analytics Ltd. All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | ||
*/ | ||
|
||
package com.snowplowanalytics.snowplow.tracker; | ||
|
||
import android.test.AndroidTestCase; | ||
|
||
public class DevicePlatformsTest extends AndroidTestCase { | ||
|
||
public void testPlatforms() { | ||
assertEquals("web", DevicePlatforms.Web.getValue()); | ||
assertEquals("mob", DevicePlatforms.Mobile.getValue()); | ||
assertEquals("pc", DevicePlatforms.Desktop.getValue()); | ||
assertEquals("srv", DevicePlatforms.ServerSideApp.getValue()); | ||
assertEquals("app", DevicePlatforms.General.getValue()); | ||
assertEquals("tv", DevicePlatforms.ConnectedTV.getValue()); | ||
assertEquals("cnsl", DevicePlatforms.GameConsole.getValue()); | ||
assertEquals("iot", DevicePlatforms.InternetOfThings.getValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...src/androidTest/java/com/snowplowanalytics/snowplow/tracker/events/EcommerceItemTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright (c) 2015 Snowplow Analytics Ltd. All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | ||
*/ | ||
|
||
package com.snowplowanalytics.snowplow.tracker.events; | ||
|
||
import android.test.AndroidTestCase; | ||
|
||
import com.snowplowanalytics.snowplow.tracker.constants.Parameters; | ||
|
||
import java.util.Map; | ||
|
||
public class EcommerceItemTest extends AndroidTestCase { | ||
|
||
public void testExpectedForm() { | ||
EcommerceTransactionItem ecommerceTransactionItem = EcommerceTransactionItem.builder() | ||
.itemId("some item id") | ||
.sku("some sku") | ||
.price(123.456) | ||
.quantity(1) | ||
.build(); | ||
|
||
Map data = ecommerceTransactionItem.getPayload().getMap(); | ||
|
||
assertNotNull(data); | ||
assertEquals("ti", data.get(Parameters.EVENT)); | ||
assertEquals("some item id", data.get(Parameters.TI_ITEM_ID)); | ||
assertEquals("some sku", data.get(Parameters.TI_ITEM_SKU)); | ||
assertEquals("123.456", data.get(Parameters.TI_ITEM_PRICE)); | ||
assertEquals("1", data.get(Parameters.TI_ITEM_QUANTITY)); | ||
assertFalse(data.containsKey(Parameters.TI_ITEM_NAME)); | ||
assertFalse(data.containsKey(Parameters.TI_ITEM_CATEGORY)); | ||
assertFalse(data.containsKey(Parameters.TI_ITEM_CURRENCY)); | ||
|
||
ecommerceTransactionItem = EcommerceTransactionItem.builder() | ||
.itemId("some item id") | ||
.sku("some sku") | ||
.price(123.456) | ||
.quantity(1) | ||
.name("some name") | ||
.category("some category") | ||
.currency("EUR") | ||
.build(); | ||
|
||
data = ecommerceTransactionItem.getPayload().getMap(); | ||
|
||
assertNotNull(data); | ||
assertEquals("ti", data.get(Parameters.EVENT)); | ||
assertEquals("some item id", data.get(Parameters.TI_ITEM_ID)); | ||
assertEquals("some sku", data.get(Parameters.TI_ITEM_SKU)); | ||
assertEquals("123.456", data.get(Parameters.TI_ITEM_PRICE)); | ||
assertEquals("1", data.get(Parameters.TI_ITEM_QUANTITY)); | ||
assertEquals("some name", data.get(Parameters.TI_ITEM_NAME)); | ||
assertEquals("some category", data.get(Parameters.TI_ITEM_CATEGORY)); | ||
assertEquals("EUR", data.get(Parameters.TI_ITEM_CURRENCY)); | ||
} | ||
|
||
public void testBuilderFailures() { | ||
boolean exception = false; | ||
try { | ||
EcommerceTransactionItem.builder().build(); | ||
} catch (Exception e) { | ||
assertEquals(null, e.getMessage()); | ||
exception = true; | ||
} | ||
assertTrue(exception); | ||
|
||
exception = false; | ||
try { | ||
EcommerceTransactionItem.builder().itemId("some item id").build(); | ||
} catch (Exception e) { | ||
assertEquals(null, e.getMessage()); | ||
exception = true; | ||
} | ||
assertTrue(exception); | ||
|
||
exception = false; | ||
try { | ||
EcommerceTransactionItem.builder().itemId("some item id").sku("some sku").build(); | ||
} catch (Exception e) { | ||
assertEquals(null, e.getMessage()); | ||
exception = true; | ||
} | ||
assertTrue(exception); | ||
|
||
exception = false; | ||
try { | ||
EcommerceTransactionItem.builder().itemId("some item id").sku("some sku").price(123.456) | ||
.build(); | ||
} catch (Exception e) { | ||
assertEquals(null, e.getMessage()); | ||
exception = true; | ||
} | ||
assertTrue(exception); | ||
|
||
exception = false; | ||
try { | ||
EcommerceTransactionItem.builder().itemId("").sku("some sku").price(123.456) | ||
.quantity(1).build(); | ||
} catch (Exception e) { | ||
assertEquals("itemId cannot be empty", e.getMessage()); | ||
exception = true; | ||
} | ||
assertTrue(exception); | ||
|
||
exception = false; | ||
try { | ||
EcommerceTransactionItem.builder().itemId("item id").sku("").price(123.456) | ||
.quantity(1).build(); | ||
} catch (Exception e) { | ||
assertEquals("sku cannot be empty", e.getMessage()); | ||
exception = true; | ||
} | ||
assertTrue(exception); | ||
} | ||
} |
119 changes: 119 additions & 0 deletions
119
...ker/src/androidTest/java/com/snowplowanalytics/snowplow/tracker/events/EcommerceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Copyright (c) 2015 Snowplow Analytics Ltd. All rights reserved. | ||
* | ||
* This program is licensed to you under the Apache License Version 2.0, | ||
* and you may not use this file except in compliance with the Apache License Version 2.0. | ||
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the Apache License Version 2.0 is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. | ||
*/ | ||
|
||
package com.snowplowanalytics.snowplow.tracker.events; | ||
|
||
import android.test.AndroidTestCase; | ||
|
||
import com.snowplowanalytics.snowplow.tracker.constants.Parameters; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Map; | ||
|
||
public class EcommerceTest extends AndroidTestCase { | ||
|
||
public void testExpectedForm() { | ||
EcommerceTransaction ecommerceTransaction = EcommerceTransaction.builder() | ||
.orderId("some order id") | ||
.totalValue(123.456) | ||
.items(new ArrayList<EcommerceTransactionItem>()) | ||
.build(); | ||
|
||
Map data = ecommerceTransaction.getPayload().getMap(); | ||
|
||
assertNotNull(data); | ||
assertEquals("tr", data.get(Parameters.EVENT)); | ||
assertEquals("some order id", data.get(Parameters.TR_ID)); | ||
assertEquals("123.456", data.get(Parameters.TR_TOTAL)); | ||
assertFalse(data.containsKey(Parameters.TR_AFFILIATION)); | ||
assertFalse(data.containsKey(Parameters.TR_TAX)); | ||
assertFalse(data.containsKey(Parameters.TR_SHIPPING)); | ||
assertFalse(data.containsKey(Parameters.TR_CITY)); | ||
assertFalse(data.containsKey(Parameters.TR_STATE)); | ||
assertFalse(data.containsKey(Parameters.TR_COUNTRY)); | ||
assertFalse(data.containsKey(Parameters.TR_CURRENCY)); | ||
|
||
EcommerceTransactionItem ecommerceTransactionItem = EcommerceTransactionItem.builder() | ||
.itemId("some item id") | ||
.sku("some sku") | ||
.price(123.456) | ||
.quantity(1) | ||
.build(); | ||
|
||
ecommerceTransaction = EcommerceTransaction.builder() | ||
.orderId("some order id") | ||
.totalValue(123.456) | ||
.affiliation("some affiliate") | ||
.taxValue(50.6) | ||
.shipping(10.0) | ||
.city("Dijon") | ||
.state("Bourgogne") | ||
.country("France") | ||
.currency("EUR") | ||
.items(ecommerceTransactionItem) | ||
.build(); | ||
|
||
data = ecommerceTransaction.getPayload().getMap(); | ||
|
||
assertNotNull(data); | ||
assertEquals("tr", data.get(Parameters.EVENT)); | ||
assertEquals("some order id", data.get(Parameters.TR_ID)); | ||
assertEquals("123.456", data.get(Parameters.TR_TOTAL)); | ||
assertEquals("some affiliate", data.get(Parameters.TR_AFFILIATION)); | ||
assertEquals("50.6", data.get(Parameters.TR_TAX)); | ||
assertEquals("10.0", data.get(Parameters.TR_SHIPPING)); | ||
assertEquals("Dijon", data.get(Parameters.TR_CITY)); | ||
assertEquals("Bourgogne", data.get(Parameters.TR_STATE)); | ||
assertEquals("France", data.get(Parameters.TR_COUNTRY)); | ||
assertEquals("EUR", data.get(Parameters.TR_CURRENCY)); | ||
} | ||
|
||
public void testBuilderFailures() { | ||
boolean exception = false; | ||
try { | ||
EcommerceTransaction.builder().build(); | ||
} catch (Exception e) { | ||
assertEquals(null, e.getMessage()); | ||
exception = true; | ||
} | ||
assertTrue(exception); | ||
|
||
exception = false; | ||
try { | ||
EcommerceTransaction.builder().orderId("some order id").build(); | ||
} catch (Exception e) { | ||
assertEquals(null, e.getMessage()); | ||
exception = true; | ||
} | ||
assertTrue(exception); | ||
|
||
exception = false; | ||
try { | ||
EcommerceTransaction.builder().orderId("some order id").totalValue(123.456).build(); | ||
} catch (Exception e) { | ||
assertEquals(null, e.getMessage()); | ||
exception = true; | ||
} | ||
assertTrue(exception); | ||
|
||
exception = false; | ||
try { | ||
EcommerceTransaction.builder().orderId("").totalValue(123.456) | ||
.items(new ArrayList<EcommerceTransactionItem>()).build(); | ||
} catch (Exception e) { | ||
assertEquals("orderId cannot be empty", e.getMessage()); | ||
exception = true; | ||
} | ||
assertTrue(exception); | ||
} | ||
} |
Oops, something went wrong.