2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.dsmr.internal.meter;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
17 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.dsmr.internal.TelegramReaderUtil;
22 import org.openhab.binding.dsmr.internal.device.cosem.CosemObject;
25 * Test class for {@link DSMRMeter}.
27 * @author Hilbrand Bouwkamp - Initial contribution
30 public class DSMRMeterTest {
33 * Test if method {@link DSMRMeter#filterMeterValues(List)} correctly filters values.
36 public void testFilterMeterValues() {
37 final List<CosemObject> cosemObjects = TelegramReaderUtil.readTelegram("dsmr_50").getCosemObjects();
39 assertMeterValues(cosemObjects, DSMRMeterType.DEVICE_V5, DSMRMeterConstants.UNKNOWN_CHANNEL, 3);
40 assertMeterValues(cosemObjects, DSMRMeterType.ELECTRICITY_V5_0, 0, 29);
41 assertMeterValues(cosemObjects, DSMRMeterType.M3_V5_0, 1, 3);
44 private void assertMeterValues(final List<CosemObject> cosemObjects, final DSMRMeterType type, final int channel,
46 final DSMRMeterDescriptor descriptor = new DSMRMeterDescriptor(type, channel);
47 final DSMRMeter meter = new DSMRMeter(descriptor);
48 final List<CosemObject> filterMeterValues = meter.filterMeterValues(cosemObjects, channel);
50 assertEquals(expected, filterMeterValues.size(), "Filter should return all required objects");