@@ -0,0 +1,2360 @@
+package com.google.sps.workspace;%0A%0Aimport static org.mockito.ArgumentMatchers.any;%0Aimport static org.mockito.ArgumentMatchers.eq;%0Aimport static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport java.io.IOException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.concurrent.ExecutionException;%0Aimport java.util.concurrent.Future;%0Aimport org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mock;%0Aimport org.mockito.junit.MockitoJUnitRunner;%0A%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class WorkspaceArchiveTest %7B%0A  @Mock Workspace workspace;%0A  @Mock Future%3CList%3CWorkspaceFile%3E%3E futureFiles;%0A  @Mock Future%3CString%3E futureString;%0A  @Mock TarArchiveOutputStream tarOut;%0A  @Mock WorkspaceFile file;%0A%0A  @Test(expected = NullPointerException.class)%0A  public void workspaceArchiveNullWorkspace() %7B%0A    new WorkspaceArchive(null);%0A  %7D%0A%0A  @Test%0A  public void archive() throws InterruptedException, ExecutionException, IOException %7B%0A    final int NUM_FILES = 3;%0A    final String FILENAME = %22FILENAME%22;%0A    final String CONTENTS = %22CONTENTS%22;%0A%0A    List%3CWorkspaceFile%3E files = new ArrayList%3C%3E();%0A    for (int i = 0; i %3C NUM_FILES; i++) %7B%0A      files.add(file);%0A    %7D%0A%0A    when(workspace.getFiles()).thenReturn(futureFiles);%0A    when(futureFiles.get()).thenReturn(files);%0A    when(file.getFilename()).thenReturn(FILENAME);%0A    when(file.getContents()).thenReturn(futureString);%0A    when(futureString.get()).thenReturn(CONTENTS);%0A%0A    new WorkspaceArchive(workspace).archive(tarOut);%0A%0A    verify(workspace, times(1)).getFiles();%0A    verify(file, times(NUM_FILES)).getFilename();%0A    verify(file, times(NUM_FILES)).getContents();%0A%0A    verify(tarOut, times(NUM_FILES)).putArchiveEntry(any());%0A    verify(tarOut, times(NUM_FILES)).write(eq(CONTENTS.getBytes()));%0A    verify(tarOut, times(NUM_FILES)).closeArchiveEntry();%0A%0A    verify(tarOut, times(1)).close();%0A  %7D%0A%0A  @Test(expected = ExecutionException.class)%0A  public void archiveException() throws InterruptedException, ExecutionException, IOException %7B%0A    when(workspace.getFiles()).thenReturn(futureFiles);%0A    when(futureFiles.get()).thenThrow(new ExecutionException(new Exception()));%0A%0A    new WorkspaceArchive(workspace).archive(tarOut);%0A  %7D%0A%7D%0A

Add WorkspaceArchiveTest