Skip to content

Commit

Permalink
First try with Java.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels committed May 11, 2024
1 parent 4b7a3e2 commit cfca547
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/Java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Java

on:
push:

jobs:
Ant:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 11 for x64
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
architecture: x64
- name: Prepare
run: find / -name "*.jar" 2>/dev/null| grep -P '(junit|hamcrest)'
- name: Run the Ant 'junit' target
run: ant -noinput -buildfile build.xml junit
- name: Debug
run: ls -lAh build
File renamed without changes.
46 changes: 46 additions & 0 deletions examples/Java/JUnitTest/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<project name="MyProject" default="junit" basedir=".">
<description>
simple example build file
</description>

<property name="src" location="src" />
<property name="test" location="test" />
<property name="build" location="build" />

<target name="init">
<tstamp />
<mkdir dir="${build}" />
</target>

<target name="compile" depends="init" description="compile the source">
<javac destdir="${build}" includeantruntime="false">
<src path="${src}" />
<src path="${test}" />
<classpath>
<pathelement location="/usr/share/java/junit.jar"/>
</classpath>
</javac>
</target>

<target name="junit" depends="compile">
<junit haltonerror="true" printsummary="true">
<classpath>
<pathelement location="/usr/share/java/junit.jar"/>
<pathelement location="/usr/share/java/hamcrest-core.jar"/>
<pathelement location="${build}"/>
</classpath>
<formatter type="xml"/>
<batchtest fork="false" todir="${build}">
<fileset dir="${test}">
<include name="**/*Test.java"/>
<include name="**/AllTests.java"/>
</fileset>
</batchtest>
</junit>
</target>

<target name="clean" description="clean up">
<delete dir="${build}" />
<delete dir="${dist}" />
</target>
</project>
7 changes: 7 additions & 0 deletions examples/Java/JUnitTest/src/my/pack/MyClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package my.pack;

public class MyClass {
boolean returnTrue() {
return false;
}
}
7 changes: 7 additions & 0 deletions examples/Java/JUnitTest/src/my/pack/OtherClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package my.pack;

public class OtherClass {
int returnThree() {
return 3;
}
}
11 changes: 11 additions & 0 deletions examples/Java/JUnitTest/test/my/AllTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package my;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({ my.pack.AllTests.class })
public class AllTests {

}
11 changes: 11 additions & 0 deletions examples/Java/JUnitTest/test/my/pack/AllTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package my.pack;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({ MyClassTest.class, OtherClassTest.class })
public class AllTests {

}
14 changes: 14 additions & 0 deletions examples/Java/JUnitTest/test/my/pack/MyClassTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package my.pack;

import static org.junit.Assert.*;

import org.junit.Test;

public class MyClassTest {

@Test
public void testReturnTrue() {
assertTrue(new MyClass().returnTrue());
}

}
14 changes: 14 additions & 0 deletions examples/Java/JUnitTest/test/my/pack/OtherClassTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package my.pack;

import static org.junit.Assert.*;

import org.junit.Test;

public class OtherClassTest {

@Test
public void testReturnThree() {
assertEquals(3, new OtherClass().returnThree());
}

}

0 comments on commit cfca547

Please sign in to comment.