|
15 | 15 | */
|
16 | 16 | package com.github.druk.dnssd;
|
17 | 17 |
|
| 18 | +import org.junit.Assert; |
18 | 19 | import org.junit.Before;
|
19 | 20 | import org.junit.Test;
|
20 | 21 | import org.junit.runner.RunWith;
|
|
28 | 29 | import android.content.Context;
|
29 | 30 | import android.os.Build;
|
30 | 31 | import android.os.Handler;
|
| 32 | +import android.text.TextUtils; |
| 33 | +import android.util.Log; |
31 | 34 |
|
32 | 35 | import java.net.Inet4Address;
|
33 | 36 | import java.net.Inet6Address;
|
34 | 37 | import java.net.InetAddress;
|
35 | 38 | import java.util.HashMap;
|
| 39 | +import java.util.Map; |
36 | 40 |
|
37 | 41 | import static org.mockito.Matchers.any;
|
38 | 42 | import static org.mockito.Matchers.anyInt;
|
@@ -220,4 +224,38 @@ public void test_query_records_failure() throws DNSSDException {
|
220 | 224 | verify(queryListener).operationFailed(any(DNSSDService.class), eq(0));
|
221 | 225 | }
|
222 | 226 |
|
| 227 | + @Test |
| 228 | + public void test_txt_record_parse_empty() { |
| 229 | + TXTRecord record = new TXTRecord(); |
| 230 | + Map<String, String> map = DNSSD.parseTXTRecords(record); |
| 231 | + Assert.assertTrue(map.isEmpty()); |
| 232 | + } |
| 233 | + |
| 234 | + @Test |
| 235 | + public void test_txt_record_parse_empty_value() { |
| 236 | + TXTRecord record = new TXTRecord(); |
| 237 | + record.set("key", (String) null); |
| 238 | + Map<String, String> map = DNSSD.parseTXTRecords(record); |
| 239 | + Assert.assertEquals(map.size(), 1); |
| 240 | + Assert.assertNull(map.get("key")); |
| 241 | + } |
| 242 | + |
| 243 | + @Test |
| 244 | + public void test_txt_record_parse_with_string_value() { |
| 245 | + TXTRecord record = new TXTRecord(); |
| 246 | + record.set("key", "value"); |
| 247 | + Map<String, String> map = DNSSD.parseTXTRecords(record); |
| 248 | + Assert.assertEquals(map.size(), 1); |
| 249 | + Assert.assertEquals(map.get("key"), "value"); |
| 250 | + } |
| 251 | + |
| 252 | + @Test |
| 253 | + public void test_txt_record_parse_with_byte_value() { |
| 254 | + TXTRecord record = new TXTRecord(); |
| 255 | + record.set("key", "value".getBytes()); |
| 256 | + Map<String, String> map = DNSSD.parseTXTRecords(record); |
| 257 | + Assert.assertEquals(map.size(), 1); |
| 258 | + Assert.assertEquals(map.get("key"), "value"); |
| 259 | + } |
| 260 | + |
223 | 261 | }
|
0 commit comments