Return to test key-value service Simple key-value service with Local Storage (test)
1: package com.voipplus.mmsclient;
2:
3: import android.content.ComponentName;
4: import android.content.Context;
5: import android.content. ;
6: import android.content.ServiceConnection;
7: import android.os.IBinder;
8:
9: import androidx.test.core.app.ApplicationProvider;
10:
11: import com.voipplus.mmsclient.serviceLocalStorage.KeyValueService;
12:
13: import org.junit.After;
14: import org.junit.Before;
15: import org.junit.Test;
16:
17: import java.util.Set;
18:
19: import static org.junit.Assert.*;
20:
21: public class KeyValueServiceTest {
22:
23: private KeyValueService keyValueService;
24: private boolean isBound = false;
25: private ServiceConnection connection;
26:
27: @Before
28: public void setUp() throws InterruptedException {
29: Context context = ApplicationProvider.getApplicationContext();
30: intent = new (context, KeyValueService.class);
31: connection = new ServiceConnection() {
32: @Override
33: public void onServiceConnected(ComponentName name, IBinder service) {
34: KeyValueService.LocalBinder binder = (KeyValueService.LocalBinder) service;
35: keyValueService = binder.getService();
36: isBound = true;
37: }
38:
39: @Override
40: public void onServiceDisconnected(ComponentName name) {
41: isBound = false;
42: }
43: };
44: context.bindService(intent, connection, Context.BIND_AUTO_CREATE);
45: Thread.sleep(1000); // Wait for service to connect
46: }
47:
48: @After
49: public void tearDown() {
50: if (isBound) {
51: Context context = ApplicationProvider.getApplicationContext();
52: context.unbindService(connection);
53: isBound = false;
54: }
55: }
56:
57: @Test
58: public void testPutAndGet() {
59: keyValueService.put("testKey", "testValue");
60: String retrievedValue = keyValueService.get("testKey");
61: assertEquals("testValue", retrievedValue);
62: }
63:
64: @Test
65: public void testRemove() {
66: keyValueService.put("testKey", "testValue");
67: keyValueService.remove("testKey");
68: String retrievedValue = keyValueService.get("testKey");
69: assertNull(retrievedValue);
70: }
71:
72: @Test
73: public void testContains() {
74: keyValueService.put("testKey", "testValue");
75: assertTrue(keyValueService.contains("testKey"));
76: assertFalse(keyValueService.contains("nonExistentKey"));
77: }
78:
79: @Test
80: public void testList() {
81: keyValueService.put("key1", "value1");
82: keyValueService.put("key2", "value2");
83: Set<String> keys = keyValueService.list();
84: assertTrue(keys.contains("key1"));
85: assertTrue(keys.contains("key2"));
86: }
87: }
88:
Return to test key-value service
AndroidMosaic context:
- 2025 year: Resolve class conflicts #AndroidMosaic
- 2025 year: Application level parameters in configuration #AndroidMosaic
- 2025 year: Create test with junit and pass or dismiss test before application launch #AndroidMosaic
- 2025 year: Ask special permission and listen answer #AndroidMosaic
- 2025 year: Service lifecycle #AndroidMosaic
- 2025 year: AtomicInteger and accept service callback in UI thread, stop progressBar that was run in UiThread #AndroidMosaic
- 2025 year: Generate random data and pass it to RecyclerView with Adapter #AndroidMosaic
- 2025 year: Pass data to new form with Intent and getParcelableExtra #AndroidMosaic
- 2025 year: Access to Contact list #AndroidMosaic
- 2025 year: Using Query and Cursor to read data sequence and fill DataAdapter for RecyclerView #AndroidMosaic
- 2025 year: Custom TabSwithcer #AndroidMosaic
- 2025 year: Custom Dropdownlist with default value based on Spinner #AndroidMosaic
- 2025 year: Create MMS service and route MMS to Emulator #AndroidMosaic
- 2025 year: Vector drawable - fastest way to create icons #AndroidMosaic
- 2025 year: Technique to create Button with own rectangle shape #AndroidMosaic
- 2025 year: Simple HTTP service #AndroidMosaic
- 2025 year: Simple key-value service with Local Storage #AndroidMosaic
- 2025 year: Cryptographic local storage key-value service #AndroidMosaic
- 2025 year: WebRTC service #AndroidMosaic
- 2025 year: SIP service #AndroidMosaic
- 2025 year: Global objects with references to all application services #AndroidMosaic
Comments (
)

Link to this page:
http://www.vb-net.com/AndroidMosaic/KeyValueServiceTest.htm
|