This project now includes an in-app mock data layer that allows you to develop and test without requiring a backend server or database connection.
-
MockDataProvider.java- Configuration file- Toggle between mock and real API with a single boolean flag
- Configure simulated network delay
-
MockDataRepository.java- Mock data storage- Contains 8 pre-configured gaming products
- Contains 3 mock users (admin, testuser, demo)
- Mock JWT token for authentication
-
MockApiWrapper.java- API wrapper- Intercepts API calls when mock mode is enabled
- Returns mock data instead of making real network requests
- Maintains the same interface as Retrofit
ApiClient.java- Initializes MockApiWrapperSignInActivity.java- Uses MockApiWrapper for loginListProductActivity.java- Uses MockApiWrapper for product listProductDetailActivity.java- Uses MockApiWrapper for product details
Open MockDataProvider.java and change the flag:
public static final boolean USE_MOCK_DATA = true; // Use mock data
public static final boolean USE_MOCK_DATA = false; // Use real APIYou can login with these pre-configured accounts:
| Username | Password | |
|---|---|---|
| admin | admin123 | admin@example.com |
| testuser | password | test@example.com |
| demo | demo | demo@example.com |
The mock repository includes 8 gaming products:
- Wireless Gaming Mouse RGB ($350,000)
- Mechanical Gaming Keyboard ($850,000)
- 7.1 Surround Gaming Headset ($450,000)
- 27" 144Hz Gaming Monitor ($3,500,000)
- Ergonomic Gaming Chair ($2,500,000)
- Gaming Laptop RTX 3060 ($25,000,000)
- Wireless Game Controller ($550,000)
- Extended RGB Mouse Pad ($180,000)
Simulate real network conditions by adjusting the delay:
public static final long MOCK_DELAY_MS = 500; // 500ms delay
public static final long MOCK_DELAY_MS = 0; // Instant response┌─────────────────┐
│ UI Activity │
└────────┬────────┘
│
↓
┌─────────────────┐ Yes ┌──────────────────┐
│ MockApiWrapper │─────────────→│ MockDataRepository│
└────────┬────────┘ └──────────────────┘
│
│ No (USE_MOCK_DATA = false)
↓
┌─────────────────┐
│ Real API │
│ (Retrofit) │
└─────────────────┘
- ✅ No Server Required - Develop without backend dependency
- ✅ Faster Development - Instant responses, no network delays
- ✅ Predictable Testing - Consistent data for UI testing
- ✅ Offline Development - Work anywhere without internet
- ✅ Easy Toggle - Switch between mock and real with one line
- ✅ Non-Destructive - All original API code remains intact
- Set
USE_MOCK_DATA = true - Run the app
- Login with
admin/admin123 - Browse products (shows 8 mock products)
- View product details
- Add items to cart
- Set
USE_MOCK_DATA = true - Login with wrong credentials (e.g.,
wrong/wrong) - Should see "Invalid credentials" error
- Set
USE_MOCK_DATA = false - Ensure backend server is running
- App will use real API calls
Edit MockDataRepository.java → initializeMockProducts():
Product p9 = new Product();
p9.productId = 9;
p9.name = "Your Product Name";
p9.description = "Description here";
p9.price = 999000;
p9.imageUrl = "https://example.com/image.jpg";
MOCK_PRODUCTS.add(p9);Edit MockDataRepository.java → initializeMockUsers():
User user4 = new User("newuser", "password123", "new@example.com");
user4.setUserId(4);
MOCK_USERS.put("newuser", user4);Solution: Make sure USE_MOCK_DATA = true in MockDataProvider.java
Solution: Check that you're using exact credentials from the table above (case-sensitive)
Solution: Verify MockDataRepository.initializeMockProducts() is called
Solution: Set USE_MOCK_DATA = false and ensure your backend server is accessible
- ✅ Mock data layer implemented
- ✅ Login authentication with mock users
- ✅ Product list with mock products
- ✅ Product details with mock data
- ✅ Configurable mock/real API toggle
- ✅ All original code preserved
Simply change one line in MockDataProvider.java:
public static final boolean USE_MOCK_DATA = false;All API calls will automatically route to your real backend server.
Ready to develop! 🚀 Your app now works with mock data by default.