diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3eaf567 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/bin/ +/.classpath +/.project diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/README.md b/README.md new file mode 100644 index 0000000..b673dc2 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +"# github-action-test" diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..c37d55e --- /dev/null +++ b/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + com.yourcompany + your-artifact-id + 1.0-SNAPSHOT + Your Project Name + + + 1.8 + 1.8 + UTF-8 + + + + + + + + org.junit.jupiter + junit-jupiter-api + 5.8.2 + test + + + + org.junit.jupiter + junit-jupiter-engine + 5.8.2 + test + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + com/MainTest.java + + + + + + + + diff --git a/src/main/java/com/Main.java b/src/main/java/com/Main.java new file mode 100644 index 0000000..528a132 --- /dev/null +++ b/src/main/java/com/Main.java @@ -0,0 +1,45 @@ +package com; + +import java.util.logging.Level; +import java.util.logging.Logger; + +public class Main { + + private static final Logger logger = Logger.getLogger(Main.class.getName()); + + public int add(int a, int b) { + try { + if (a < 0 || b < 0) { + throw new IllegalArgumentException("Both numbers must be non-negative."); + } + if (Integer.MAX_VALUE - a < b) { + throw new ArithmeticException("Integer overflow when trying to add " + a + " + " + b); + } + int result = a + b; + logger.log(Level.INFO, "Successfully added {0} and {1} to get {2}", new Object[]{a, b, result}); + return result; + } catch (IllegalArgumentException | ArithmeticException e) { + logger.log(Level.SEVERE, "Exception caught during addition: " + e.getMessage()); + throw e; // Re-throwing the exception to let the caller know an error occurred + } + } + + public static void main(String[] args) { + Main calculator = new Main(); + + // Test cases + System.out.println("Test Case 1 (5 + 5): " + calculator.add(5, 5)); + System.out.println("Test Case 2 (Integer.MAX_VALUE + 1):"); + try { + calculator.add(Integer.MAX_VALUE, 1); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + System.out.println("Test Case 3 (-1 + 5):"); + try { + calculator.add(-1, 5); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } +} diff --git a/src/test/java/com/MainTest.java b/src/test/java/com/MainTest.java new file mode 100644 index 0000000..c2448cc --- /dev/null +++ b/src/test/java/com/MainTest.java @@ -0,0 +1,16 @@ +package com; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +class MainTest { + + @Test + void test() { + Main main = new Main(); + int result = main.add(1, 1); + assertEquals(2, result); + } + +}