@Override public Log create() { return new CustomPropertiesLog(); } }
/** * Send custom properties. * Unit test requires top level methods when PowerMock.whenNew. * * @param properties properties to send. */ @WorkerThread private void queueCustomProperties(@NonNull Map<String, Object> properties) { CustomPropertiesLog customPropertiesLog = new CustomPropertiesLog(); customPropertiesLog.setProperties(properties); mChannel.enqueue(customPropertiesLog, CORE_GROUP, Flags.DEFAULTS); }
@Test public void compareDifferentType() { TestUtils.compareSelfNullClass(new CustomPropertiesLog()); }
@Test(expected = JSONException.class) public void serializeWithInvalidType() throws JSONException { LogSerializer serializer = new DefaultLogSerializer(); CustomPropertiesLog invalidTypeLog = new CustomPropertiesLog(); invalidTypeLog.setTimestamp(new Date()); Map<String, Object> invalidTypeProperties = new HashMap<>(); invalidTypeProperties.put("nested", new HashMap<String, Object>()); invalidTypeLog.setProperties(invalidTypeProperties); serializer.serializeLog(invalidTypeLog); }
@Test(expected = JSONException.class) public void serializeWithoutProperties() throws JSONException { LogSerializer serializer = new DefaultLogSerializer(); CustomPropertiesLog invalidTypeLog = new CustomPropertiesLog(); invalidTypeLog.setTimestamp(new Date()); serializer.serializeLog(invalidTypeLog); }
@Test public void customPropertiesLog() throws JSONException { CustomPropertiesLog log = new CustomPropertiesLog(); Map<String, Object> properties = new HashMap<>(); properties.put("t1", "test"); properties.put("t2", new Date(0)); properties.put("t3", 0); properties.put("t4", false); //noinspection ConstantConditions properties.put("t5", null); log.setProperties(properties); UUID sid = UUIDUtils.randomUUID(); log.setSid(sid); log.setTimestamp(new Date()); /* Verify serialize and deserialize. */ LogSerializer serializer = new DefaultLogSerializer(); serializer.addLogFactory(CustomPropertiesLog.TYPE, new CustomPropertiesLogFactory()); String payload = serializer.serializeLog(log); Log actualContainer = serializer.deserializeLog(payload, null); assertEquals(log, actualContainer); }
@Test public void compare() { /* Empty objects. */ CustomPropertiesLog a = new CustomPropertiesLog(); CustomPropertiesLog b = new CustomPropertiesLog(); checkEquals(a, b); checkEquals(a.getType(), CustomPropertiesLog.TYPE); UUID sid = UUIDUtils.randomUUID(); a.setSid(sid); checkNotEquals(a, b); b.setSid(sid); checkEquals(a, b); /* Properties. */ Map<String, Object> properties = new HashMap<>(); properties.put("test", "test"); a.setProperties(properties); checkEquals(a.getProperties(), properties); checkNotEquals(a, b); b.setProperties(new HashMap<String, Object>()); checkNotEquals(a, b); b.setProperties(properties); checkEquals(a, b); } }