Skip to content

Commit

Permalink
added tests for class path service
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadsebak committed Jun 21, 2015
1 parent 02978f1 commit a151093
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ClasspathService(@NotNull Project project) {
* @param hostLibraries
* @return targetLibraries
*/
public List<File> deltaOfDeployedJars(List<File> hostLibraries) throws IOException, RuntimeConfigurationException {
public List<File> deltaOfDeployedJars(List<File> hostLibraries) {
List<File> newLibraries = new ArrayList<File>();
for (File hostFile : hostLibraries) {
if (!hostFile.getName().contains("jar")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void verifyUploadToTarget() throws RuntimeConfigurationException, IOExcep
@Test
public void verifyJavaCommands() throws IOException, RuntimeConfigurationException, ClassNotFoundException {
final String path = FileUtilities.SEPARATOR + "home" + FileUtilities.SEPARATOR + "ahmad" + FileUtilities.SEPARATOR + "IdeaProjects" + FileUtilities.SEPARATOR + "untitled";
final String commandToBeExecuted = "mkdir -p " + path + "; " + "cd " + path + "; rm -rf *;";
final String commandToBeExecuted = "mkdir -p " + path + "; " + "cd " + path + "; mkdir -p classes; mkdir -p lib; " + "cd " + path + FileUtilities.SEPARATOR + FileUtilities.CLASSES + "; rm -rf *;";
Mockito.when(sshClient.isAuthenticated()).thenReturn(true);
Mockito.when(project.getName()).thenReturn("untitled");
Mockito.when(sshClient.isConnected()).thenReturn(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.atsebak.embeddedlinuxjvm.services;

import com.intellij.openapi.project.Project;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ClasspathServiceTest {
private final Project project = mock(Project.class);
private ClasspathService classpathService;
private File jar1 = mock(File.class);
private File jar2 = mock(File.class);
private File output = mock(File.class);
private List<File> hostFiles;

@Before
public void setUp() throws Exception {
classpathService = new ClasspathService(project);
hostFiles = Arrays.asList(jar1, jar2, output);
when(jar1.getName()).thenReturn("randomjar1.jar");
when(jar2.getName()).thenReturn("randomjar2.jar");
when(output.getName()).thenReturn("untitledproject");
}

@Test
public void testFirstDeployment() {
List<File> filesToDeploy = classpathService.deltaOfDeployedJars(hostFiles);
assertEquals(filesToDeploy, hostFiles);
}

@Test
public void testSecondDeployment() {
List<File> filesToDeploy = classpathService.deltaOfDeployedJars(hostFiles);
assertEquals(filesToDeploy, hostFiles);
filesToDeploy = classpathService.deltaOfDeployedJars(hostFiles);
assertEquals(filesToDeploy, Arrays.asList(output));
}
}

0 comments on commit a151093

Please sign in to comment.