]> git.basschouten.com Git - openhab-addons.git/blob
25962d5e004359c1f548326feea32de45430342c
[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.mybmw.internal.handler.backend;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.junit.jupiter.api.Assertions.assertFalse;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.Test;
20 import org.openhab.binding.mybmw.internal.util.FileReader;
21
22 /**
23  * 
24  * checks if the response anonymization is successful
25  * 
26  * @author Martin Grassl - initial contribution
27  */
28 @NonNullByDefault
29 public class ResponseContentAnonymizerTest {
30     @Test
31     void testAnonymizeResponseContent() {
32         String content = FileReader.fileToString("responses/vehicles.json");
33         String anonymous = ResponseContentAnonymizer.anonymizeResponseContent(content);
34         assertFalse(anonymous.contains("VIN1234567"), "VIN not deleted!");
35         assertFalse(anonymous.contains("Testort"), "Location not deleted!");
36     }
37
38     @Test
39     void testAnonymizeRandomString() {
40         String content = "asdfiulsahföauifhnasdölfam,xöasiocjfsailfunsalifnsaölfkmasdäf.ifnvaskdfnvinlocationasdfiulsdanf";
41         String anonymous = ResponseContentAnonymizer.anonymizeResponseContent(content);
42         assertEquals(content, anonymous);
43     }
44
45     @Test
46     void testAnonymizeEmptyString() {
47         String content = "";
48         String anonymous = ResponseContentAnonymizer.anonymizeResponseContent(content);
49         assertEquals(content, anonymous);
50     }
51
52     @Test
53     void testAnonymizeNullString() {
54         String content = null;
55         String anonymous = ResponseContentAnonymizer.anonymizeResponseContent(content);
56         assertEquals("", anonymous);
57     }
58 }