diff --git a/.gitignore b/.gitignore index 656557ccda3ed8ca9ba9ed971379baa3bf1f21f4..cfd3bd84273939dd2b791f830461bd9f8686c547 100644 --- a/.gitignore +++ b/.gitignore @@ -23,5 +23,18 @@ target .idea *.iml +# Eclipse stuff +bin +.project +.classpath +.settings + +# OS stuff +.DS_Store +__MACOSX +._* +Desktop.ini +Thumbs.db + # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* diff --git a/README.md b/README.md index 6fe088ee6458f438b37b9305de2c645915c21ff4..0852b61c7b9b041dad2140c434426dd641156644 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,79 @@ Simple skeleton with libgdx. ## Known bugs + + +# Maven Setup +This project comes with a working Maven `pom.xml` file. You should be able to import it into Eclipse using *File → Import → Maven → Existing Maven Projects* (or *Check out Maven Projects from SCM* to do Git cloning as well). You can also build the project from the command line with `mvn compile` and test it with `mvn test`. + +Pay attention to these folders: +* `src/main/java` – Java source files go here (as usual for Maven) +* `src/main/resources` – data files go here +* `src/test/java` – JUnit tests +* `target/classes` – compiled Java class files + +You should probably edit the `pom.xml` and fill in details such as the project `name` and `artifactId`: + + +```xml + + < !-- FIXME - set group id --> + <groupId>inf112.skeleton.app</groupId> + < !-- FIXME - set artifact name --> + <artifactId>mvn-app</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> + + < !-- FIXME - set app name --> + <name>mvn-app</name> + < !-- FIXME change it to the project's website --> + <url>http://www.example.com</url> +``` + + +## Running +You can run the project from Eclipse, or with Maven using `mvn exec:java`. Change the main class by modifying the `main.class` setting in `pom.xml`: + +``` + <main.class>inf112.skeleton.app.Main</main.class> +``` + +If you run `mvn package` you'll get a everything bundled up into a JAR file +* `target/*.jar` – your compiled project, packaged in a JAR file + +#### POM snippets +If you're setting up / adding ANTLR4 to your own project, you can cut and paste these lines into your `pom.xml`file. + +* You should make sure that both the parser generator and the runtime use the same version, so define the version number in `<properties>…</properties>`: + +```xml + <antlr4.version>4.8-1</antlr4.version> +``` + +* The ANTLR4 runtime is needed to run the compiled parser; add it in the `<depencencies>…</dependencies>` section: + +```xml +<!-- https://mvnrepository.com/artifact/org.antlr/antlr4-runtime --> +<dependency> + <groupId>org.antlr</groupId> + <artifactId>antlr4-runtime</artifactId> + <version>${antlr4.version}</version> +</dependency> +``` + +* The ANTLR4 maven plugin includes the ANTLR4 tool, and is needed to generate parser during compilation; add it to `<build><plugins>…</plugins></build>`: + +```xml +<plugin> + <groupId>org.antlr</groupId> + <artifactId>antlr4-maven-plugin</artifactId> + <version>${antlr4.version}</version> + <executions> + <execution> + <goals> + <goal>antlr4</goal> + </goals> + </execution> + </executions> +</plugin> +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index 86d80131d0d965b7a45f6db66941b453122dd694..49752055506335c2baea7e247373a2fe8372293f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,94 +1,144 @@ <?xml version="1.0" encoding="UTF-8"?> -<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> +<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>inf112.skeleton.app</groupId> - <artifactId>mvn-app</artifactId> - <version>1.0-SNAPSHOT</version> + <!-- FIXME - set group id --> + <groupId>inf112.skeleton.app</groupId> + <!-- FIXME - set artifact name --> + <artifactId>mvn-app</artifactId> + <version>1.0-SNAPSHOT</version> + <packaging>jar</packaging> - <name>mvn-app</name> - <!-- FIXME change it to the project's website --> - <url>http://www.example.com</url> + <!-- FIXME - set app name --> + <name>mvn-app</name> + <!-- FIXME change it to the project's website --> + <url>http://www.example.com</url> - <properties> - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> - <maven.compiler.release>9</maven.compiler.release> - </properties> + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <maven.compiler.release>17</maven.compiler.release> + <libgdx.version>1.10.0</libgdx.version> + <!-- FIXME - set to app's main class' --> + <main.class>inf112.skeleton.app.Main</main.class> + </properties> - <dependencies> - <!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx --> - <dependency> - <groupId>com.badlogicgames.gdx</groupId> - <artifactId>gdx</artifactId> - <version>1.9.10</version> - </dependency> + <dependencies> + <!--libGDX graphics library – https://libgdx.com/ --> + <dependency> + <groupId>com.badlogicgames.gdx</groupId> + <artifactId>gdx</artifactId> + <version>${libgdx.version}</version> + </dependency> - <dependency> - <groupId>com.badlogicgames.gdx</groupId> - <artifactId>gdx-platform</artifactId> - <version>1.9.10</version> - <classifier>natives-desktop</classifier> - </dependency> + <!-- Platform-specific libraries --> + <dependency> + <groupId>com.badlogicgames.gdx</groupId> + <artifactId>gdx-platform</artifactId> + <version>${libgdx.version}</version> + <classifier>natives-desktop</classifier> + </dependency> - <dependency> - <groupId>com.badlogicgames.gdx</groupId> - <artifactId>gdx-backend-lwjgl3</artifactId> - <version>1.9.10</version> - </dependency> + <dependency> + <groupId>com.badlogicgames.gdx</groupId> + <artifactId>gdx-backend-lwjgl3</artifactId> + <version>${libgdx.version}</version> + </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.11</version> - <scope>test</scope> - </dependency> - </dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>5.5.2</version> + <scope>test</scope> + </dependency> + </dependencies> - <build> - <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> - <plugins> - <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> - <plugin> - <artifactId>maven-clean-plugin</artifactId> - <version>3.1.0</version> - </plugin> - <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> - <plugin> - <artifactId>maven-resources-plugin</artifactId> - <version>3.0.2</version> - </plugin> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <version>3.8.0</version> - </plugin> - <plugin> - <artifactId>maven-surefire-plugin</artifactId> - <version>2.22.1</version> - </plugin> - <plugin> - <artifactId>maven-jar-plugin</artifactId> - <version>3.0.2</version> - </plugin> - <plugin> - <artifactId>maven-install-plugin</artifactId> - <version>2.5.2</version> - </plugin> - <plugin> - <artifactId>maven-deploy-plugin</artifactId> - <version>2.8.2</version> - </plugin> - <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> - <plugin> - <artifactId>maven-site-plugin</artifactId> - <version>3.7.1</version> - </plugin> - <plugin> - <artifactId>maven-project-info-reports-plugin</artifactId> - <version>3.0.0</version> - </plugin> - </plugins> - </pluginManagement> - </build> -</project> + <build> + <plugins> + <!-- Run app through Maven --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <configuration> + <mainClass>${main.class}</mainClass> + </configuration> + </plugin> + <!-- Build a fat uber-jar with all dependencies --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-shade-plugin</artifactId> + <version>2.3</version> + <executions> + <execution> + <phase>package</phase> + <goals> + <goal>shade</goal> + </goals> + <configuration> + <transformers> + <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> + <manifestEntries> + <Main-Class>${main.class}</Main-Class> + </manifestEntries> + </transformer> + <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> + </transformers> + <artifactSet></artifactSet> + <outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + <pluginManagement> + <!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> + <plugins> + <plugin> + <artifactId>maven-clean-plugin</artifactId> + <version>3.1.0</version> + </plugin> + <plugin> + <artifactId>maven-site-plugin</artifactId> + <version>3.7.1</version> + </plugin> + <plugin> + <artifactId>maven-project-info-reports-plugin</artifactId> + <version>3.0.0</version> + </plugin> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <version>3.0.2</version> + </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.0</version> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <version>3.0.0-M5</version> + <configuration> + <useModulePath>false</useModulePath> + <argLine></argLine> + </configuration> + </plugin> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <version>3.0.2</version> + </plugin> + <plugin> + <artifactId>maven-install-plugin</artifactId> + <version>2.5.2</version> + </plugin> + <plugin> + <artifactId>maven-deploy-plugin</artifactId> + <version>2.8.2</version> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>exec-maven-plugin</artifactId> + <version>1.6.0</version> + </plugin> + </plugins> + </pluginManagement> + </build> +</project> \ No newline at end of file diff --git a/src/test/java/inf112/skeleton/app/AppTest.java b/src/test/java/inf112/skeleton/app/AppTest.java index 18d3d591fbe33eb37c3e94c181f5629bfbac9eaa..30fb9171956c67648acac6fa081163e6cb7b26de 100644 --- a/src/test/java/inf112/skeleton/app/AppTest.java +++ b/src/test/java/inf112/skeleton/app/AppTest.java @@ -1,17 +1,58 @@ package inf112.skeleton.app; -import static org.junit.Assert.assertTrue; -import org.junit.Test; +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.*; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; -/** - * Unit test for simple App. - */ public class AppTest { - /** - * Rigorous Test :-) - */ - @Test - public void shouldAnswerWithTrue() { - assertTrue(true); - } -} + /** + * Static method run before everything else + */ + @BeforeAll + static void setUpBeforeAll() { + } + + /** + * Setup method called before each of the test methods + */ + @BeforeEach + void setUpBeforeEach() { + } + + /** + * Simple test case + */ + @Test + void dummy1() { + // Expected result is the first argument, value to be tested is the second. + // The message is optional. + assertEquals("foo", "f".concat("oo"), "fooo?"); + } + + /** + * Simple test case + */ + @Test + void dummy2() { + // For floats and doubles it's best to use assertEquals with a delta, since + // floating-point numbers are imprecise + float a = 100000; + a = a + 0.1f; + assertEquals(100000.1, a, 0.01); + } + + /** + * Parameterized test case, reading arguments from comma-separated strings + * + * @param a + * @param b + * @param c + */ + @CsvSource(value = { "1,1,2", "1,2,3", "2,3,5", "3,5,8", "5,8,13", "8,13,21" }) + @ParameterizedTest(name = "{0}+{1} == {2}") + void addTest(int a, int b, int c) { + assertEquals(c, a + b); + } +} \ No newline at end of file