1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.net.wifi;
18 
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 
22 import androidx.test.filters.SmallTest;
23 
24 import org.junit.Test;
25 
26 import java.nio.charset.StandardCharsets;
27 
28 /**
29  * Unit tests for {@link android.net.wifi.WifiSsid}.
30  */
31 @SmallTest
32 public class WifiSsidTest {
33 
34     private static final String TEST_SSID = "Test SSID";
35     private static final byte[] TEST_SSID_BYTES = TEST_SSID.getBytes(StandardCharsets.US_ASCII);
36 
37     /**
38      * Check that createFromByteArray() works.
39      */
40     @Test
testCreateFromByteArray()41     public void testCreateFromByteArray() {
42         WifiSsid wifiSsid = WifiSsid.createFromByteArray(TEST_SSID_BYTES);
43         assertTrue(wifiSsid != null);
44         assertEquals(TEST_SSID, wifiSsid.toString());
45     }
46 
47     /**
48      * Verify that SSID created from byte array and string with the same content are equal.
49      *
50      * @throws Exception
51      */
52     @Test
testEquals()53     public void testEquals() throws Exception {
54         WifiSsid fromBytes = WifiSsid.createFromByteArray(TEST_SSID_BYTES);
55         WifiSsid fromString = WifiSsid.createFromAsciiEncoded(TEST_SSID);
56         assertTrue(fromBytes != null);
57         assertTrue(fromString != null);
58         assertEquals(fromBytes, fromString);
59     }
60 }
61