### Question:
EventConstraintDecorator implements InternalEvent { @Override public synchronized void addMetric(String name, Double value) { if (name != null && value != null) { if (currentNumOfAttributesAndMetrics.get() < maxAttributesAndMetrics && !decoratedEvent.hasMetric(name)) { Pair<String, Double> trimmedResult = processMetric(name, value); decoratedEvent.addMetric(trimmedResult.getKey(), trimmedResult.getValue()); currentNumOfAttributesAndMetrics.incrementAndGet(); } else if (decoratedEvent.hasMetric(name)) { Pair<String, Double> trimmedResult = processMetric(name, value); decoratedEvent.addMetric(trimmedResult.getKey(), trimmedResult.getValue()); } } } EventConstraintDecorator(InternalEvent eventToDecorate, int maxAttributesAndMetrics); static EventConstraintDecorator newInstance(InternalEvent eventToDecorate); @Override synchronized void addAttribute(String name, String value); @Override boolean hasAttribute(String attributeName); @Override synchronized void addMetric(String name, Double value); @Override boolean hasMetric(String metricName); @Override String getEventType(); @Override String getAttribute(String name); @Override Double getMetric(String name); @Override AnalyticsEvent withAttribute(String name, String value); @Override AnalyticsEvent withMetric(String name, Double value); @Override Map<String, String> getAllAttributes(); @Override Map<String, Double> getAllMetrics(); @Override JSONObject toJSONObject(); @Override Long getEventTimestamp(); @Override Id getUniqueId(); @Override String getSessionId(); @Override long getSessionStart(); @Override Long getSessionStop(); @Override Long getSessionDuration(); @Override String getSdkName(); @Override String getSdkVersion(); @Override ClientContext createClientContext(String networkType);  }### Answer:
@Test public void test_addMetric_limit() { for (double i = 0.0; i < 100; i++) { target.addMetric(String.valueOf(i), i); } verify(eventToWrap, times(EventConstraintDecorator.MAX_NUM_OF_METRICS_AND_ATTRIBUTES)) .addMetric(anyString(), anyDouble()); }
@Test public void test_addMetric_nullKey() { for (double i = 0; i < 100; i++) { target.addMetric(null, i); } verify(eventToWrap, times(0)).addMetric(anyString(), anyDouble()); }
@Test public void test_addMetric_null_value() { for (double i = 0; i < 100; i++) { target.addMetric(String.valueOf(i), null); } verify(eventToWrap, times(0)).addMetric(anyString(), anyDouble()); }
@Test public void test_addMetric_clipped_string() { String tooLongKey = "123456789012345678901234567890123456789012345678901234567890"; target.addMetric(tooLongKey, 123.456); verify(eventToWrap, times(1)).addMetric( tooLongKey.substring(0, EventConstraintDecorator.MAX_EVENT_ATTRIBUTE_METRIC_KEY_LENGTH), 123.456); }