Skip to content

Commit

Permalink
Much more Google calendar testing
Browse files Browse the repository at this point in the history
  • Loading branch information
burnflare committed Nov 6, 2016
1 parent 6ca4c2e commit a5c980a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
Binary file added StoredCredentialForTesting
Binary file not shown.
63 changes: 57 additions & 6 deletions src/test/java/seedu/agendum/sync/SyncProviderGoogleTests.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,77 @@
package seedu.agendum.sync;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.internal.matchers.Any;
import seedu.agendum.model.task.Task;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.util.Optional;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
import static seedu.agendum.commons.core.Config.DEFAULT_DATA_DIR;

public class SyncProviderGoogleTests {
private SyncProviderGoogle syncProviderGoogle;
private static final File DATA_STORE_CREDENTIAL = new File(DEFAULT_DATA_DIR + "StoredCredential");
private static final File DATA_STORE_CREDENTIAL_TEST = new File("StoredCredentialForTesting");

private SyncProviderGoogle syncProviderGoogle;
private SyncManager mockSyncManager;

@Before
public void setUp() {
syncProviderGoogle = new SyncProviderGoogle();
try {
Files.copy(DATA_STORE_CREDENTIAL_TEST.toPath(), DATA_STORE_CREDENTIAL.toPath());
} catch (IOException e) {
e.printStackTrace();
}

mockSyncManager = mock(SyncManager.class);
syncProviderGoogle = spy(new SyncProviderGoogle());
syncProviderGoogle.setManager(mockSyncManager);
}

@After
public void tearDown() {
syncProviderGoogle.stop();
}

@Test
public void syncProviderGoogle_start_calendarAlreadyExists() {
syncProviderGoogle.deleteAgendumCalendar();
syncProviderGoogle.start();

verify(mockSyncManager).setSyncStatus(Sync.SyncStatus.RUNNING);
}

@Test
public void syncProviderGoogle_start_createCalendar() {
syncProviderGoogle.start();

verify(mockSyncManager).setSyncStatus(Sync.SyncStatus.RUNNING);
}

@Test
public void syncProviderGoogle_startIfNeeded_credentialsFound() {
syncProviderGoogle.startIfNeeded();
verify(syncProviderGoogle).start();
}

@Test
public void addevent() {
public void syncProviderGoogle_startIfNeeded_credentialsNotFound() {
DATA_STORE_CREDENTIAL.delete();
syncProviderGoogle.startIfNeeded();
verify(syncProviderGoogle, never()).start();
}

@Test
public void syncProviderGoogle_addEvent_successful() {
syncProviderGoogle.start();

Task mockTask = mock(Task.class);
Optional<LocalDateTime> fakeTime = Optional.of(LocalDateTime.now());

Expand All @@ -33,7 +82,9 @@ public void addevent() {
}

@Test
public void deleteEvent() {
public void syncProviderGoogle_deleteEvent_successful() {
syncProviderGoogle.start();

Task mockTask = mock(Task.class);
Optional<LocalDateTime> fakeTime = Optional.of(LocalDateTime.now());

Expand Down

0 comments on commit a5c980a

Please sign in to comment.