// 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.lecturechat.data;

import static org.junit.Assert.assertEquals;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Query;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public final class DatastoreAccessTest {

  private final LocalServiceTestHelper helper =
      new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
  
  private DatastoreAccess datastore;

  @Before
  public void setUp() {
    helper.setUp();
    datastore = DatastoreAccess.getDatastoreAccess();
  }

  @After
  public void tearDown() {
    helper.tearDown();
  }

  @Test
  public void getAllGroupsReturnsCorrectNumberOfGroups1() {
    List<Group> groups = datastore.getAllGroups();
    assertEquals(0, groups.size());
  }
}
@@ -1284,16 +1284,68 @@
 Test %7B%0A%0A
+  private final String groupEntityLabel = %22Group%22;%0A%0A
   privat
@@ -1384,16 +1384,16 @@
 elper =%0A
-
       ne
@@ -1496,16 +1496,52 @@
 tastore;
+%0A  private DatastoreService service;
 %0A%0A  @Bef
@@ -1584,24 +1584,85 @@
 er.setUp();%0A
+    service = DatastoreServiceFactory.getDatastoreService();%0A
     datastor
@@ -1798,49 +1798,653 @@
 oid 
-getAllGroupsReturnsCorrectNumberOfGroups1
+addGroupAddsExactlyOneGroup() %7B%0A    String university = %22A%22;%0A    String degree = %22B%22;%0A    int year = 1;%0A%0A%0A    datastore.addGroup(university, degree, year);%0A%0A%0A    assertEquals(1, service.prepare(new Query(groupEntityLabel)).countEntities());%0A  %7D%0A%0A  @Test%0A  public void addGroupDoesntAddAlreadyExistingGroup() %7B%0A    String university = %22A%22;%0A    String degree = %22B%22;%0A    int year = 1;%0A    datastore.addGroup(university, degree, year);%0A%0A%0A    datastore.addGroup(university, degree, year);%0A%0A%0A    assertEquals(1, service.prepare(new Query(groupEntityLabel)).countEntities());%0A  %7D%0A%0A  @Test%0A  public void getAllGroupsReturnsEmptyListIfNoGroupsInDatastore
 () %7B
@@ -2491,24 +2491,26 @@
 llGroups();%0A
+%0A%0A
     assertEq
@@ -2537,9 +2537,429 @@
 ));%0A  %7D%0A
-%7D
+%0A  @Test%0A  public void getAllGroupsReturnsCorrectNumberOfGroups() %7B%0A    String university1 = %22A%22;%0A    String degree1 = %22B%22;%0A    int year1 = 1;%0A    String university2 = %22C%22;%0A    String degree2 = %22D%22;%0A    int year2 = 1;%0A    datastore.addGroup(university1, degree1, year1);%0A    datastore.addGroup(university2, degree2, year2);%0A%0A%0A    List%3CGroup%3E groups = datastore.getAllGroups();%0A%0A%0A    assertEquals(2, groups.size());%0A  %7D%0A%7D%0A

Add some unit tests