-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit cef62cb
Showing
6 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/bin/ | ||
/.classpath | ||
/.project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"# github-action-test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |