From a15109362f889e32eb13933f3b8c3c6a44be5e26 Mon Sep 17 00:00:00 2001 From: ahmadsebak Date: Sun, 21 Jun 2015 08:54:51 -0400 Subject: [PATCH] added tests for class path service --- .../services/ClasspathService.java | 2 +- .../protocol/ssh/SSHHandlerTargetTest.java | 2 +- .../services/ClasspathServiceTest.java | 45 +++++++++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/com/atsebak/embeddedlinuxjvm/services/ClasspathServiceTest.java diff --git a/src/com/atsebak/embeddedlinuxjvm/services/ClasspathService.java b/src/com/atsebak/embeddedlinuxjvm/services/ClasspathService.java index 7c9d986..3af5090 100644 --- a/src/com/atsebak/embeddedlinuxjvm/services/ClasspathService.java +++ b/src/com/atsebak/embeddedlinuxjvm/services/ClasspathService.java @@ -35,7 +35,7 @@ public ClasspathService(@NotNull Project project) { * @param hostLibraries * @return targetLibraries */ - public List deltaOfDeployedJars(List hostLibraries) throws IOException, RuntimeConfigurationException { + public List deltaOfDeployedJars(List hostLibraries) { List newLibraries = new ArrayList(); for (File hostFile : hostLibraries) { if (!hostFile.getName().contains("jar")) { diff --git a/test/com/atsebak/embeddedlinuxjvm/protocol/ssh/SSHHandlerTargetTest.java b/test/com/atsebak/embeddedlinuxjvm/protocol/ssh/SSHHandlerTargetTest.java index ca50534..16fddd0 100644 --- a/test/com/atsebak/embeddedlinuxjvm/protocol/ssh/SSHHandlerTargetTest.java +++ b/test/com/atsebak/embeddedlinuxjvm/protocol/ssh/SSHHandlerTargetTest.java @@ -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); diff --git a/test/com/atsebak/embeddedlinuxjvm/services/ClasspathServiceTest.java b/test/com/atsebak/embeddedlinuxjvm/services/ClasspathServiceTest.java new file mode 100644 index 0000000..148065d --- /dev/null +++ b/test/com/atsebak/embeddedlinuxjvm/services/ClasspathServiceTest.java @@ -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 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 filesToDeploy = classpathService.deltaOfDeployedJars(hostFiles); + assertEquals(filesToDeploy, hostFiles); + } + + @Test + public void testSecondDeployment() { + List filesToDeploy = classpathService.deltaOfDeployedJars(hostFiles); + assertEquals(filesToDeploy, hostFiles); + filesToDeploy = classpathService.deltaOfDeployedJars(hostFiles); + assertEquals(filesToDeploy, Arrays.asList(output)); + } +} \ No newline at end of file