Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
RRFRRF committed Nov 8, 2024
0 parents commit cef62cb
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/bin/
/.classpath
/.project
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"# github-action-test"
53 changes: 53 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.yourcompany</groupId>
<artifactId>your-artifact-id</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Your Project Name</name>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- Other dependencies -->

<!-- JUnit 5 (Jupiter) API and Engine dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.2</version> <!-- Use the latest version available -->
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<!-- Specify the test you want to run -->
<includes>
<include>com/MainTest.java</include>
</includes>
</configuration>
</plugin>

<!-- other plugins like maven-compiler-plugin, etc. -->
</plugins>
</build>
</project>
45 changes: 45 additions & 0 deletions src/main/java/com/Main.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
16 changes: 16 additions & 0 deletions src/test/java/com/MainTest.java
Original file line number Diff line number Diff line change
@@ -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);
}

}

0 comments on commit cef62cb

Please sign in to comment.