]> git.basschouten.com Git - openhab-addons.git/blob
76e362ec34d1bad50a76026496b23644760aeed6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.vdr.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.vdr.internal.svdrp.SVDRPChannel;
20 import org.openhab.binding.vdr.internal.svdrp.SVDRPDiskStatus;
21 import org.openhab.binding.vdr.internal.svdrp.SVDRPException;
22 import org.openhab.binding.vdr.internal.svdrp.SVDRPParseResponseException;
23
24 /**
25  * Specific unit tests to check if {@link SVDRPDiskStatus} parses SVDRP responses correctly
26  *
27  * @author Matthias Klocke - Initial contribution
28  *
29  */
30 @NonNullByDefault
31 public class SVDRPDiskStatusTest {
32
33     private final String diskStatusResponseOk = "411266MB 30092MB 92%";
34     private final String diskStatusResponseParseError1 = "411266MB  30092MB  92%";
35     private final String diskStatusResponseParseError2 = "411266MB 30092 92%";
36     private final String diskStatusResponseParseError3 = "42b3MB 30092MB 92%";
37
38     @Test
39     public void testParseDiskStatus() throws SVDRPException {
40         SVDRPDiskStatus diskStatus = SVDRPDiskStatus.parse(diskStatusResponseOk);
41         assertEquals(411266, diskStatus.getMegaBytesTotal());
42         assertEquals(30092, diskStatus.getMegaBytesFree());
43         assertEquals(92, diskStatus.getPercentUsed());
44     }
45
46     @Test
47     public void testParseExceptionDiskStatus() {
48         assertThrows(SVDRPParseResponseException.class, () -> {
49             SVDRPChannel.parse(diskStatusResponseParseError1);
50         });
51         assertThrows(SVDRPParseResponseException.class, () -> {
52             SVDRPChannel.parse(diskStatusResponseParseError2);
53         });
54         assertThrows(SVDRPParseResponseException.class, () -> {
55             SVDRPChannel.parse(diskStatusResponseParseError3);
56         });
57     }
58 }