diff --git a/CHANGELOG.md b/CHANGELOG.md
index 046df4b..cc7d0a9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,11 +2,30 @@
All notable changes to this project will be documented in this file.
+## [3.0.0] - 2023-02-15
+
+### Changed
+- Update log4j dependency from 2.18.0 to 2.19.0
+- Update maven-assembly-plugin dependency from 3.4.1 to 3.4.2
+- Improve logger logic in ModuleRunner
+- Renamed class from CommandHelper to CommandExecutor
+
+### Added
+
+- Unit tests and unit tests dependencies: JUnit and mockito
+- Created ModuleTypeEnum to store module name and commands
+- Created OpSystemEnum to store OS runner and option
+
+### Removed
+
+- Formatter class
+- OsHelper class
+
## [2.0.0] - 2022-07-05
### Changed
-- Update log4j dependency from 1.17.2 to 1.18.0
+- Update log4j dependency from 2.17.2 to 2.18.0
- Update maven-assembly-plugin dependency from 3.3.0 to 3.4.0
- Split Scriptum class in other two classes
- Change jar entry point from Scriptum class to Main class
diff --git a/pom.xml b/pom.xml
index 1f1a12f..bb4d053 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
br.com.gaboso
scriptum
- 2.0.0
+ 3.0.0
com.github.gaboso
@@ -32,7 +32,10 @@
UTF-8
1.8
1.8
- 2.18.0
+ 2.19.0
+ 5.9.0
+ 5.1.1
+ 3.0.0-M8
@@ -46,6 +49,31 @@
log4j-core
${log.version}
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-params
+ ${junit.version}
+ test
+
+
+ org.mockito
+ mockito-core
+ ${mockito.version}
+ test
+
+
+ org.mockito
+ mockito-junit-jupiter
+ ${mockito.version}
+ test
+
+
@@ -55,7 +83,7 @@
org.apache.maven.plugins
maven-assembly-plugin
- 3.4.1
+ 3.4.2
@@ -77,6 +105,12 @@
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${surefire-plugin.version}
+
diff --git a/src/main/java/com/github/gaboso/ModuleRunner.java b/src/main/java/com/github/gaboso/ModuleRunner.java
index 77377f3..cea54ee 100644
--- a/src/main/java/com/github/gaboso/ModuleRunner.java
+++ b/src/main/java/com/github/gaboso/ModuleRunner.java
@@ -1,11 +1,15 @@
package com.github.gaboso;
+import com.github.gaboso.helper.CommandExecutor;
import com.github.gaboso.module.GitModule;
import com.github.gaboso.module.Module;
+import com.github.gaboso.module.ModuleTypeEnum;
import com.github.gaboso.module.impl.BowerModule;
import com.github.gaboso.module.impl.GruntModule;
import com.github.gaboso.module.impl.MavenModule;
import com.github.gaboso.module.impl.NpmModule;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import java.io.File;
import java.util.Arrays;
@@ -17,28 +21,38 @@
*/
public class ModuleRunner {
+ private static final Logger LOGGER = LogManager.getLogger(ModuleRunner.class.getName());
+
+ private final GitModule gitModule;
+
private final List modules;
public ModuleRunner() {
- Module bowerModule = new BowerModule();
- Module gruntModule = new GruntModule();
- Module mavenModule = new MavenModule();
- Module npmModule = new NpmModule();
- modules = Arrays.asList(bowerModule, gruntModule, mavenModule, npmModule);
+ CommandExecutor commandExecutor = new CommandExecutor();
+
+ this.gitModule = new GitModule(commandExecutor);
+
+ this.modules = Arrays.asList(
+ new BowerModule(commandExecutor),
+ new GruntModule(commandExecutor),
+ new MavenModule(commandExecutor),
+ new NpmModule(commandExecutor)
+ );
}
public void runAll(List folders) {
- for (File folder : folders) {
- run(folder);
- }
+ folders.forEach(this::run);
}
public void run(File folder) {
String path = folder.getPath();
String folderName = folder.getName();
- if (GitModule.isProject(path)) {
- GitModule.executeCommands(folderName, path);
+ if (gitModule.isProject(path)) {
+ String typeName = ModuleTypeEnum.GIT.getTypeName();
+ printStartMessage(typeName, folderName);
+ gitModule.executeCommands(path);
+ printFinishMessage(typeName, folderName);
}
File[] listFiles = folder.listFiles();
@@ -46,11 +60,22 @@ public void run(File folder) {
return;
}
- for (Module module : modules) {
- if (module.isProject(listFiles)) {
- module.executeCommands(folderName, path);
- }
- }
+ modules.stream()
+ .filter(module -> module.isProject(listFiles))
+ .forEach(module -> {
+ String typeName = module.getType().getTypeName();
+ printStartMessage(typeName, folderName);
+ module.executeCommands(path);
+ printFinishMessage(typeName, folderName);
+ });
+ }
+
+ private void printStartMessage(String typeName, String folderName) {
+ LOGGER.info("--------- Starting update {} --- [ {} ] ---------", typeName, folderName);
+ }
+
+ private void printFinishMessage(String typeName, String folderName) {
+ LOGGER.info("--------- Finished update {} --- [ {} ] ---------", typeName, folderName);
}
}
diff --git a/src/main/java/com/github/gaboso/format/Formatter.java b/src/main/java/com/github/gaboso/format/Formatter.java
deleted file mode 100644
index d5157e5..0000000
--- a/src/main/java/com/github/gaboso/format/Formatter.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.github.gaboso.format;
-
-/**
- * @since 1.3.2
- * Log message Formatter
- */
-public class Formatter {
-
- private final String type;
- private final String projectName;
-
- public Formatter(String type, String projectName) {
- this.type = type;
- this.projectName = projectName;
- }
-
- public String getMessageStartUpdate() {
- return String.format("Updating %s project --- [ %s ]", type, projectName);
- }
-
- public String getMessageFinishUpdate() {
- return String.format("Finish update %s project --- [ %s ]", type, projectName);
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/github/gaboso/helper/CommandHelper.java b/src/main/java/com/github/gaboso/helper/CommandExecutor.java
similarity index 69%
rename from src/main/java/com/github/gaboso/helper/CommandHelper.java
rename to src/main/java/com/github/gaboso/helper/CommandExecutor.java
index 3e66153..297639c 100644
--- a/src/main/java/com/github/gaboso/helper/CommandHelper.java
+++ b/src/main/java/com/github/gaboso/helper/CommandExecutor.java
@@ -1,6 +1,6 @@
package com.github.gaboso.helper;
-import com.github.gaboso.format.Formatter;
+import com.github.gaboso.os.OpSystemEnum;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -12,18 +12,14 @@
* @since 1.0
* Command Helper
*/
-public class CommandHelper {
+public class CommandExecutor {
- private static final Logger LOGGER = LogManager.getLogger(CommandHelper.class.getName());
+ private static final Logger LOGGER = LogManager.getLogger(CommandExecutor.class.getName());
- private CommandHelper() {
- }
-
- public static void executeCMD(String path, String cmd, Formatter formatter) {
- LOGGER.info(formatter.getMessageStartUpdate());
-
- String runner = OsHelper.getRunner();
- String option = OsHelper.getOption();
+ public void executeCMD(String path, String cmd) {
+ OpSystemEnum currentOs = OpSystemEnum.getCurrentOs();
+ String runner = currentOs.getRunner();
+ String option = currentOs.getOption();
String command = "cd " + path + "/ && " + cmd;
@@ -46,7 +42,6 @@ public static void executeCMD(String path, String cmd, Formatter formatter) {
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
- LOGGER.info(formatter.getMessageFinishUpdate());
}
}
diff --git a/src/main/java/com/github/gaboso/helper/OsHelper.java b/src/main/java/com/github/gaboso/helper/OsHelper.java
deleted file mode 100644
index 65be826..0000000
--- a/src/main/java/com/github/gaboso/helper/OsHelper.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.github.gaboso.helper;
-
-/**
- * @since 1.3.3
- * Operational System Helper
- */
-public class OsHelper {
-
- private OsHelper() {
- }
-
- public static String getRunner() {
- return isWindows() ? "cmd.exe" : "/bin/bash";
- }
-
- private static boolean isWindows() {
- return System.getProperty("os.name").contains("Windows");
- }
-
- public static String getOption() {
- return isWindows() ? "/c" : "-c";
- }
-
-}
\ No newline at end of file
diff --git a/src/main/java/com/github/gaboso/module/GitModule.java b/src/main/java/com/github/gaboso/module/GitModule.java
index ebfd563..024c9b6 100644
--- a/src/main/java/com/github/gaboso/module/GitModule.java
+++ b/src/main/java/com/github/gaboso/module/GitModule.java
@@ -1,8 +1,7 @@
package com.github.gaboso.module;
-import com.github.gaboso.format.Formatter;
-import com.github.gaboso.helper.CommandHelper;
-import com.github.gaboso.helper.OsHelper;
+import com.github.gaboso.helper.CommandExecutor;
+import com.github.gaboso.os.OpSystemEnum;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -18,12 +17,16 @@ public class GitModule {
private static final Logger LOGGER = LogManager.getLogger(GitModule.class.getName());
- private GitModule() {
+ private final CommandExecutor commandExecutor;
+
+ public GitModule(CommandExecutor commandExecutor) {
+ this.commandExecutor = commandExecutor;
}
- public static boolean isProject(String path) {
- String runner = OsHelper.getRunner();
- String option = OsHelper.getOption();
+ public boolean isProject(String path) {
+ OpSystemEnum currentOs = OpSystemEnum.getCurrentOs();
+ String runner = currentOs.getRunner();
+ String option = currentOs.getOption();
ProcessBuilder builder = new ProcessBuilder(runner, option, "cd " + path + "/ && git rev-parse --is-inside-work-tree");
builder.redirectErrorStream(true);
@@ -40,10 +43,9 @@ public static boolean isProject(String path) {
return false;
}
- public static void executeCommands(String projectName, String projectPath) {
- Formatter formatter = new Formatter("Git", projectName);
-
- CommandHelper.executeCMD(projectPath, "git fetch && git pull origin", formatter);
+ public void executeCommands(String projectPath) {
+ String command = ModuleTypeEnum.GIT.getCommand();
+ commandExecutor.executeCMD(projectPath, command);
}
}
diff --git a/src/main/java/com/github/gaboso/module/Module.java b/src/main/java/com/github/gaboso/module/Module.java
index 6fd9e7a..1471c95 100644
--- a/src/main/java/com/github/gaboso/module/Module.java
+++ b/src/main/java/com/github/gaboso/module/Module.java
@@ -6,6 +6,8 @@ public interface Module {
boolean isProject(File[] listFiles);
- void executeCommands(String projectName, String projectPath);
+ void executeCommands(String projectPath);
+
+ ModuleTypeEnum getType();
}
diff --git a/src/main/java/com/github/gaboso/module/ModuleTypeEnum.java b/src/main/java/com/github/gaboso/module/ModuleTypeEnum.java
new file mode 100644
index 0000000..2d27e4e
--- /dev/null
+++ b/src/main/java/com/github/gaboso/module/ModuleTypeEnum.java
@@ -0,0 +1,30 @@
+package com.github.gaboso.module;
+
+/**
+ * @since 3.0.0
+ * ModuleTypeEnum
+ */
+public enum ModuleTypeEnum {
+
+ MAVEN("Maven", "mvn clean install -DskipTests=true"),
+ GRUNT("Grunt", "grunt"),
+ BOWER("Bower", "bower install && bower update"),
+ NPM("NPM", "npm install && npm update"),
+ GIT("Git", "git fetch && git pull origin");
+
+ private final String typeName;
+ private final String command;
+
+ ModuleTypeEnum(String name, String command) {
+ this.typeName = name;
+ this.command = command;
+ }
+
+ public String getTypeName() {
+ return typeName;
+ }
+
+ public String getCommand() {
+ return command;
+ }
+}
diff --git a/src/main/java/com/github/gaboso/module/impl/BowerModule.java b/src/main/java/com/github/gaboso/module/impl/BowerModule.java
index ff3096b..b84f20e 100644
--- a/src/main/java/com/github/gaboso/module/impl/BowerModule.java
+++ b/src/main/java/com/github/gaboso/module/impl/BowerModule.java
@@ -1,8 +1,8 @@
package com.github.gaboso.module.impl;
-import com.github.gaboso.format.Formatter;
-import com.github.gaboso.helper.CommandHelper;
+import com.github.gaboso.helper.CommandExecutor;
import com.github.gaboso.module.Module;
+import com.github.gaboso.module.ModuleTypeEnum;
import java.io.File;
import java.util.Arrays;
@@ -14,20 +14,30 @@
*/
public class BowerModule implements Module {
+ private final CommandExecutor commandExecutor;
+
+ public BowerModule(CommandExecutor commandExecutor) {
+ this.commandExecutor = commandExecutor;
+ }
+
@Override
public boolean isProject(File[] listFiles) {
return Arrays.stream(listFiles)
- .filter(Objects::nonNull)
- .filter(file -> !file.isDirectory())
- .map(File::getName)
- .anyMatch("bower.json"::equals);
+ .filter(Objects::nonNull)
+ .filter(file -> !file.isDirectory())
+ .map(File::getName)
+ .anyMatch("bower.json"::equals);
}
@Override
- public void executeCommands(String projectName, String projectPath) {
- Formatter formatter = new Formatter("Bower", projectName);
+ public void executeCommands(String projectPath) {
+ String command = this.getType().getCommand();
+ commandExecutor.executeCMD(projectPath, command);
+ }
- CommandHelper.executeCMD(projectPath, "bower install && bower update", formatter);
+ @Override
+ public ModuleTypeEnum getType() {
+ return ModuleTypeEnum.BOWER;
}
}
diff --git a/src/main/java/com/github/gaboso/module/impl/GruntModule.java b/src/main/java/com/github/gaboso/module/impl/GruntModule.java
index 45998c7..8f71e63 100644
--- a/src/main/java/com/github/gaboso/module/impl/GruntModule.java
+++ b/src/main/java/com/github/gaboso/module/impl/GruntModule.java
@@ -1,8 +1,8 @@
package com.github.gaboso.module.impl;
-import com.github.gaboso.format.Formatter;
-import com.github.gaboso.helper.CommandHelper;
+import com.github.gaboso.helper.CommandExecutor;
import com.github.gaboso.module.Module;
+import com.github.gaboso.module.ModuleTypeEnum;
import java.io.File;
import java.util.Arrays;
@@ -14,20 +14,30 @@
*/
public class GruntModule implements Module {
+ private final CommandExecutor commandExecutor;
+
+ public GruntModule(CommandExecutor commandExecutor) {
+ this.commandExecutor = commandExecutor;
+ }
+
@Override
public boolean isProject(File[] listFiles) {
return Arrays.stream(listFiles)
- .filter(Objects::nonNull)
- .filter(file -> !file.isDirectory())
- .map(File::getName)
- .anyMatch("gruntfile.js"::equals);
+ .filter(Objects::nonNull)
+ .filter(file -> !file.isDirectory())
+ .map(File::getName)
+ .anyMatch("gruntfile.js"::equalsIgnoreCase);
}
@Override
- public void executeCommands(String projectName, String projectPath) {
- Formatter formatter = new Formatter("Grunt", projectName);
+ public void executeCommands(String projectPath) {
+ String command = this.getType().getCommand();
+ commandExecutor.executeCMD(projectPath, command);
+ }
- CommandHelper.executeCMD(projectPath, "grunt", formatter);
+ @Override
+ public ModuleTypeEnum getType() {
+ return ModuleTypeEnum.GRUNT;
}
}
diff --git a/src/main/java/com/github/gaboso/module/impl/MavenModule.java b/src/main/java/com/github/gaboso/module/impl/MavenModule.java
index 563bcae..e368036 100644
--- a/src/main/java/com/github/gaboso/module/impl/MavenModule.java
+++ b/src/main/java/com/github/gaboso/module/impl/MavenModule.java
@@ -1,8 +1,8 @@
package com.github.gaboso.module.impl;
-import com.github.gaboso.format.Formatter;
-import com.github.gaboso.helper.CommandHelper;
+import com.github.gaboso.helper.CommandExecutor;
import com.github.gaboso.module.Module;
+import com.github.gaboso.module.ModuleTypeEnum;
import java.io.File;
import java.util.Arrays;
@@ -14,20 +14,30 @@
*/
public class MavenModule implements Module {
+ private final CommandExecutor commandExecutor;
+
+ public MavenModule(CommandExecutor commandExecutor) {
+ this.commandExecutor = commandExecutor;
+ }
+
@Override
public boolean isProject(File[] listFiles) {
return Arrays.stream(listFiles)
- .filter(Objects::nonNull)
- .filter(file -> !file.isDirectory())
- .map(File::getName)
- .anyMatch("pom.xml"::equals);
+ .filter(Objects::nonNull)
+ .filter(file -> !file.isDirectory())
+ .map(File::getName)
+ .anyMatch("pom.xml"::equals);
}
@Override
- public void executeCommands(String projectName, String projectPath) {
- Formatter formatter = new Formatter("Maven", projectName);
+ public void executeCommands(String projectPath) {
+ String command = this.getType().getCommand();
+ commandExecutor.executeCMD(projectPath, command);
+ }
- CommandHelper.executeCMD(projectPath, "mvn clean install -DskipTests=true", formatter);
+ @Override
+ public ModuleTypeEnum getType() {
+ return ModuleTypeEnum.MAVEN;
}
}
diff --git a/src/main/java/com/github/gaboso/module/impl/NpmModule.java b/src/main/java/com/github/gaboso/module/impl/NpmModule.java
index baf11b9..a37d417 100644
--- a/src/main/java/com/github/gaboso/module/impl/NpmModule.java
+++ b/src/main/java/com/github/gaboso/module/impl/NpmModule.java
@@ -1,8 +1,8 @@
package com.github.gaboso.module.impl;
-import com.github.gaboso.format.Formatter;
-import com.github.gaboso.helper.CommandHelper;
+import com.github.gaboso.helper.CommandExecutor;
import com.github.gaboso.module.Module;
+import com.github.gaboso.module.ModuleTypeEnum;
import java.io.File;
import java.util.Arrays;
@@ -14,20 +14,30 @@
*/
public class NpmModule implements Module {
+ private final CommandExecutor commandExecutor;
+
+ public NpmModule(CommandExecutor commandExecutor) {
+ this.commandExecutor = commandExecutor;
+ }
+
@Override
public boolean isProject(File[] listFiles) {
return Arrays.stream(listFiles)
- .filter(Objects::nonNull)
- .filter(file -> !file.isDirectory())
- .map(File::getName)
- .anyMatch("package.json"::equals);
+ .filter(Objects::nonNull)
+ .filter(file -> !file.isDirectory())
+ .map(File::getName)
+ .anyMatch("package.json"::equals);
}
@Override
- public void executeCommands(String projectName, String projectPath) {
- Formatter formatter = new Formatter("NPM", projectName);
+ public void executeCommands(String projectPath) {
+ String command = this.getType().getCommand();
+ commandExecutor.executeCMD(projectPath, command);
+ }
- CommandHelper.executeCMD(projectPath, "npm install && npm update", formatter);
+ @Override
+ public ModuleTypeEnum getType() {
+ return ModuleTypeEnum.NPM;
}
}
diff --git a/src/main/java/com/github/gaboso/os/OpSystemEnum.java b/src/main/java/com/github/gaboso/os/OpSystemEnum.java
new file mode 100644
index 0000000..520efdc
--- /dev/null
+++ b/src/main/java/com/github/gaboso/os/OpSystemEnum.java
@@ -0,0 +1,32 @@
+package com.github.gaboso.os;
+
+/**
+ * @since 3.0.0
+ * OpSystemEnum
+ */
+public enum OpSystemEnum {
+
+ WINDOWS("cmd.exe", "/c"),
+ LINUX("/bin/bash", "-c");
+
+ private final String runner;
+ private final String option;
+
+ OpSystemEnum(String runner, String option) {
+ this.runner = runner;
+ this.option = option;
+ }
+
+ public String getRunner() {
+ return runner;
+ }
+
+ public String getOption() {
+ return option;
+ }
+
+ public static OpSystemEnum getCurrentOs() {
+ return System.getProperty("os.name").contains("Windows") ? WINDOWS : LINUX;
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/github/gaboso/module/impl/BowerModuleTest.java b/src/test/java/com/github/gaboso/module/impl/BowerModuleTest.java
new file mode 100644
index 0000000..2dbbe92
--- /dev/null
+++ b/src/test/java/com/github/gaboso/module/impl/BowerModuleTest.java
@@ -0,0 +1,54 @@
+package com.github.gaboso.module.impl;
+
+import com.github.gaboso.helper.CommandExecutor;
+import com.github.gaboso.module.ModuleTypeEnum;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.io.File;
+
+@ExtendWith(MockitoExtension.class)
+class BowerModuleTest {
+
+ @Mock
+ CommandExecutor commandExecutor;
+
+ @InjectMocks
+ BowerModule bowerModule;
+
+ @Test
+ void isProject_WithValidFile_ReturnsTrue() throws NullPointerException {
+ File bowerJson = new File(getClass().getResource("/valid/bower/bower.json").getFile());
+ File[] listFiles = {bowerJson};
+ boolean result = bowerModule.isProject(listFiles);
+ Assertions.assertTrue(result);
+ }
+
+ @Test
+ void isProject_WithInvalidFile_ReturnsFalse() throws NullPointerException {
+ File file = new File(getClass().getResource("/invalid/image.jpg").getFile());
+ File[] listFiles = {file};
+ boolean result = bowerModule.isProject(listFiles);
+ Assertions.assertFalse(result);
+ }
+
+ @Test
+ void executeCommands_ShouldCallCommandExecutor() {
+ bowerModule.executeCommands("myProjectUsingBowerPath");
+
+ Mockito.verify(commandExecutor, Mockito.times(1))
+ .executeCMD("myProjectUsingBowerPath", ModuleTypeEnum.BOWER.getCommand());
+ }
+
+ @Test
+ void getType_ReturnsBower() {
+ ModuleTypeEnum result = bowerModule.getType();
+ Assertions.assertEquals(ModuleTypeEnum.BOWER, result);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/github/gaboso/module/impl/GruntModuleTest.java b/src/test/java/com/github/gaboso/module/impl/GruntModuleTest.java
new file mode 100644
index 0000000..0a06227
--- /dev/null
+++ b/src/test/java/com/github/gaboso/module/impl/GruntModuleTest.java
@@ -0,0 +1,54 @@
+package com.github.gaboso.module.impl;
+
+import com.github.gaboso.helper.CommandExecutor;
+import com.github.gaboso.module.ModuleTypeEnum;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.io.File;
+
+@ExtendWith(MockitoExtension.class)
+class GruntModuleTest {
+
+ @Mock
+ CommandExecutor commandExecutor;
+
+ @InjectMocks
+ GruntModule gruntModule;
+
+ @Test
+ void isProject_WithValidFile_ReturnsTrue() throws NullPointerException {
+ File gruntfileJs = new File(getClass().getResource("/valid/grunt/gruntfile.js").getFile());
+ File[] listFiles = {gruntfileJs};
+ boolean result = gruntModule.isProject(listFiles);
+ Assertions.assertTrue(result);
+ }
+
+ @Test
+ void isProject_WithInvalidFile_ReturnsFalse() throws NullPointerException {
+ File file = new File(getClass().getResource("/invalid/image.jpg").getFile());
+ File[] listFiles = {file};
+ boolean result = gruntModule.isProject(listFiles);
+ Assertions.assertFalse(result);
+ }
+
+ @Test
+ void executeCommands_ShouldCallCommandExecutor() {
+ gruntModule.executeCommands("myProjectUsingGruntPath");
+
+ Mockito.verify(commandExecutor, Mockito.times(1))
+ .executeCMD("myProjectUsingGruntPath", ModuleTypeEnum.GRUNT.getCommand());
+ }
+
+ @Test
+ void getType_ReturnsGrunt() {
+ ModuleTypeEnum type = gruntModule.getType();
+ Assertions.assertEquals(ModuleTypeEnum.GRUNT, type);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/github/gaboso/module/impl/MavenModuleTest.java b/src/test/java/com/github/gaboso/module/impl/MavenModuleTest.java
new file mode 100644
index 0000000..9a9b5bc
--- /dev/null
+++ b/src/test/java/com/github/gaboso/module/impl/MavenModuleTest.java
@@ -0,0 +1,54 @@
+package com.github.gaboso.module.impl;
+
+import com.github.gaboso.helper.CommandExecutor;
+import com.github.gaboso.module.ModuleTypeEnum;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.io.File;
+
+@ExtendWith(MockitoExtension.class)
+class MavenModuleTest {
+
+ @Mock
+ CommandExecutor commandExecutor;
+
+ @InjectMocks
+ MavenModule mavenModule;
+
+ @Test
+ void isProject_WithValidFile_ReturnsTrue() throws NullPointerException {
+ File pomXml = new File(getClass().getResource("/valid/maven/pom.xml").getFile());
+ File[] listFiles = {pomXml};
+ boolean result = mavenModule.isProject(listFiles);
+ Assertions.assertTrue(result);
+ }
+
+ @Test
+ void isProject_WithInvalidFile_ReturnsFalse() throws NullPointerException {
+ File file = new File(getClass().getResource("/invalid/image.jpg").getFile());
+ File[] listFiles = {file};
+ boolean result = mavenModule.isProject(listFiles);
+ Assertions.assertFalse(result);
+ }
+
+ @Test
+ void executeCommands_ShouldCallCommandExecutor() {
+ mavenModule.executeCommands("myProjectUsingMavenPath");
+
+ Mockito.verify(commandExecutor, Mockito.times(1))
+ .executeCMD("myProjectUsingMavenPath", ModuleTypeEnum.MAVEN.getCommand());
+ }
+
+ @Test
+ void getType_ReturnsMaven() {
+ ModuleTypeEnum type = mavenModule.getType();
+ Assertions.assertEquals(ModuleTypeEnum.MAVEN, type);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/github/gaboso/module/impl/NpmModuleTest.java b/src/test/java/com/github/gaboso/module/impl/NpmModuleTest.java
new file mode 100644
index 0000000..6d3129f
--- /dev/null
+++ b/src/test/java/com/github/gaboso/module/impl/NpmModuleTest.java
@@ -0,0 +1,54 @@
+package com.github.gaboso.module.impl;
+
+import com.github.gaboso.helper.CommandExecutor;
+import com.github.gaboso.module.ModuleTypeEnum;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.io.File;
+
+@ExtendWith(MockitoExtension.class)
+class NpmModuleTest {
+
+ @Mock
+ CommandExecutor commandExecutor;
+
+ @InjectMocks
+ NpmModule npmModule;
+
+ @Test
+ void isProject_WithValidFile_ReturnsTrue() throws NullPointerException {
+ File packageJson = new File(getClass().getResource("/valid/npm/package.json").getFile());
+ File[] listFiles = {packageJson};
+ boolean result = npmModule.isProject(listFiles);
+ Assertions.assertTrue(result);
+ }
+
+ @Test
+ void isProject_WithInvalidFile_ReturnsFalse() throws NullPointerException {
+ File file = new File(getClass().getResource("/invalid/image.jpg").getFile());
+ File[] listFiles = {file};
+ boolean result = npmModule.isProject(listFiles);
+ Assertions.assertFalse(result);
+ }
+
+ @Test
+ void executeCommands_ShouldCallCommandExecutor() {
+ npmModule.executeCommands("myProjectUsingNpmPath");
+
+ Mockito.verify(commandExecutor, Mockito.times(1))
+ .executeCMD("myProjectUsingNpmPath", ModuleTypeEnum.NPM.getCommand());
+ }
+
+ @Test
+ void getType_ReturnsNpm() {
+ ModuleTypeEnum type = npmModule.getType();
+ Assertions.assertEquals(ModuleTypeEnum.NPM, type);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/github/gaboso/os/OpSystemEnumTest.java b/src/test/java/com/github/gaboso/os/OpSystemEnumTest.java
new file mode 100644
index 0000000..01f1884
--- /dev/null
+++ b/src/test/java/com/github/gaboso/os/OpSystemEnumTest.java
@@ -0,0 +1,33 @@
+package com.github.gaboso.os;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class OpSystemEnumTest {
+
+ @Test
+ void windows_GetOption_AssertTrue() {
+ String result = OpSystemEnum.WINDOWS.getOption();
+ Assertions.assertEquals("/c", result);
+ }
+
+ @Test
+ void windows_GetRunner_AssertTrue() {
+ String result = OpSystemEnum.WINDOWS.getRunner();
+ Assertions.assertEquals("cmd.exe", result);
+ }
+
+ @Test
+ void linux_GetOption_AssertTrue() {
+ String result = OpSystemEnum.LINUX.getOption();
+ Assertions.assertEquals("-c", result);
+ }
+
+ @Test
+ void linux_GetRunner_AssertTrue() {
+ String result = OpSystemEnum.LINUX.getRunner();
+ Assertions.assertEquals("/bin/bash", result);
+ }
+
+
+}
\ No newline at end of file
diff --git a/src/test/resources/invalid/image.jpg b/src/test/resources/invalid/image.jpg
new file mode 100644
index 0000000..1914264
Binary files /dev/null and b/src/test/resources/invalid/image.jpg differ
diff --git a/src/test/resources/valid/bower/bower.json b/src/test/resources/valid/bower/bower.json
new file mode 100644
index 0000000..1030407
--- /dev/null
+++ b/src/test/resources/valid/bower/bower.json
@@ -0,0 +1,8 @@
+{
+ "name": "example-app",
+ "version": "0.0.1",
+ "main": "public/javascripts/app.js",
+ "dependencies": {
+ "lodash": "~4.0.0"
+ }
+}
\ No newline at end of file
diff --git a/src/test/resources/valid/grunt/gruntfile.js b/src/test/resources/valid/grunt/gruntfile.js
new file mode 100644
index 0000000..00ec2a7
--- /dev/null
+++ b/src/test/resources/valid/grunt/gruntfile.js
@@ -0,0 +1,23 @@
+module.exports = function (grunt) {
+
+ grunt.initConfig({
+ jshint: {
+ files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
+ options: {
+ globals: {
+ jQuery: true
+ }
+ }
+ },
+ watch: {
+ files: ['<%= jshint.files %>'],
+ tasks: ['jshint']
+ }
+ });
+
+ grunt.loadNpmTasks('grunt-contrib-jshint');
+ grunt.loadNpmTasks('grunt-contrib-watch');
+
+ grunt.registerTask('default', ['jshint']);
+
+};
\ No newline at end of file
diff --git a/src/test/resources/valid/maven/pom.xml b/src/test/resources/valid/maven/pom.xml
new file mode 100644
index 0000000..8829086
--- /dev/null
+++ b/src/test/resources/valid/maven/pom.xml
@@ -0,0 +1,6 @@
+
+ 4.0.0
+ com.mycompany.app
+ my-app
+ 1
+
\ No newline at end of file
diff --git a/src/test/resources/valid/npm/package.json b/src/test/resources/valid/npm/package.json
new file mode 100644
index 0000000..11ff496
--- /dev/null
+++ b/src/test/resources/valid/npm/package.json
@@ -0,0 +1,4 @@
+{
+ "name": "my-program",
+ "version": "1.2.5"
+}
\ No newline at end of file