/*
Copyright 2020 Google LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package com.google.gpay.virtualqueue.backendservice.repository;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.google.gpay.virtualqueue.backendservice.model.Shop;
import com.google.gpay.virtualqueue.backendservice.model.Token;
import com.google.gpay.virtualqueue.backendservice.model.Shop.ShopStatus;
import com.google.gpay.virtualqueue.backendservice.model.Token.Status;
import com.google.gpay.virtualqueue.backendservice.proto.CreateShopRequest;
import static com.google.gpay.virtualqueue.backendservice.repository.InMemoryVirtualQueueRepository.WAITING_TIME_MINS;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = InMemoryVirtualQueueRepository.class)
public class InMemoryVirtualQueueRepositoryTest {
    InMemoryVirtualQueueRepository inMemoryVirtualQueueRepository = new InMemoryVirtualQueueRepository();

    private static final String SHOP_OWNER_ID = "uid";
    private static final String SHOP_NAME = "shopName";
    private static final String SHOP_ADDRESS = "address";
    private static final String PHONE_NUMBER = "+919012192800";
    private static final String SHOP_TYPE = "shopType";

    @BeforeEach
    public void setUp(){
        inMemoryVirtualQueueRepository.getTokenMap().clear();
        inMemoryVirtualQueueRepository.getShopMap().clear();
        inMemoryVirtualQueueRepository.getShopIdToListOfTokensMap().clear();
        inMemoryVirtualQueueRepository.getShopIdToLastAllotedTokenMap().clear();
        inMemoryVirtualQueueRepository.getShopOwnerMap().clear();
    }

    @Test
    public void testCreateShop() throws Exception {
        CreateShopRequest shop = new CreateShopRequest(SHOP_OWNER_ID, SHOP_NAME, SHOP_ADDRESS, PHONE_NUMBER, SHOP_TYPE);

        UUID shopId = inMemoryVirtualQueueRepository.createShop(shop);

        assertEquals("Size of shopMap", 1, inMemoryVirtualQueueRepository.getShopMap().size());
        assertEquals("Shop Owner Id ", SHOP_OWNER_ID, inMemoryVirtualQueueRepository.getShopMap().get(shopId).getShopOwnerId());
        assertEquals("Shop Name ", SHOP_NAME, inMemoryVirtualQueueRepository.getShopMap().get(shopId).getShopName());
        assertEquals("Shop Address ", SHOP_ADDRESS, inMemoryVirtualQueueRepository.getShopMap().get(shopId).getAddress());
        assertEquals("Shop Phone Number ", PHONE_NUMBER, inMemoryVirtualQueueRepository.getShopMap().get(shopId).getPhoneNumber());
        assertEquals("Shop Type ", SHOP_TYPE, inMemoryVirtualQueueRepository.getShopMap().get(shopId).getShopType());
    }
    
    @Test
    public void testGetWaitingTime() throws Exception {
        long waitingTime = inMemoryVirtualQueueRepository.getWaitingTime();
        
        assertEquals("Waiting Time per customer is", WAITING_TIME_MINS, waitingTime);
    }

    @Test
    public void testGetTokens_success() throws Exception {
        UUID shopId = UUID.randomUUID();
        Shop shop = new Shop();
        shop.setStatus(ShopStatus.ACTIVE);
        inMemoryVirtualQueueRepository.getShopMap().put(shopId, shop);
        List<Token> tokens = new ArrayList<>();
        tokens.add(new Token(UUID.randomUUID(), shopId, 1, Status.ACTIVE));
        inMemoryVirtualQueueRepository.getShopIdToListOfTokensMap().put(shopId, tokens);

        List<Token> expectedGetTokensResponseList = inMemoryVirtualQueueRepository.getTokens(shopId);

        assertEquals("Size of token list", expectedGetTokensResponseList.size(), inMemoryVirtualQueueRepository.getShopIdToListOfTokensMap().get(shopId).size());
    }
}

@@ -2449,32 +2449,620 @@
 clear();%0A    %7D%0A%0A
+    public UUID AddShopToRepository()%7B%0A        Shop shop = new Shop(SHOP_OWNER_ID, SHOP_NAME, SHOP_ADDRESS, PHONE_NUMBER, SHOP_TYPE);%0A        shop.setStatus(ShopStatus.ACTIVE);%0A        UUID shopId = UUID.randomUUID();%0A        inMemoryVirtualQueueRepository.getShopMap().put(shopId, shop);%0A        return shopId;%0A    %7D%0A%0A    public void AddTokenListToShop(UUID shopId)%7B%0A        List%3CToken%3E tokens = new ArrayList%3C%3E();%0A        tokens.add(new Token(UUID.randomUUID(), shopId, 1, Status.ACTIVE));%0A        inMemoryVirtualQueueRepository.getShopIdToListOfTokensMap().put(shopId, tokens);%0A    %7D%0A%0A
     @Test%0A    pu
@@ -3099,32 +3099,51 @@
 ows Exception %7B%0A
+        // Arrange%0A
         CreateSh
@@ -3244,24 +3244,39 @@
 HOP_TYPE);%0A%0A
+        // Act%0A
         UUID
@@ -3331,24 +3331,42 @@
 hop(shop);%0A%0A
+        // Assert%0A
         asse
@@ -4405,72 +4405,38 @@
     
-UUID shopId = UUID.randomUUID();%0A        Shop shop = new
+// Arrange%0A        // Add
  Shop
-();
 %0A   
@@ -4444,246 +4444,120 @@
     
-shop.setStatus(ShopStatus.ACTIVE);%0A        inMemoryVirtualQueueRepository.getShopMap().put(shopId, shop);%0A        List%3CToken%3E tokens = new ArrayList%3C%3E();%0A        tokens.add(new Token(UUID.randomUUID(), shopId, 1, Status.ACTIVE)
+UUID shopId = AddShopToRepository();%0A        // Add list of tokens%0A        AddTokenListToShop(shopId
 );%0A
+%0A
         
 inMe
@@ -4556,89 +4556,14 @@
     
-inMemoryVirtualQueueRepository.getShopIdToListOfTokensMap().put(shopId, tokens);%0A
+// Act
 %0A   
@@ -4654,32 +4654,50 @@
 okens(shopId);%0A%0A
+        // Assert%0A
         assertEq

Create functions AddShopToRepository and AddTokenListToShop