Skip to content

Simple Java Example #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: java
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# java-example
[![Build Status](https://travis-ci.org/travis-ci-examples/java-example.svg?branch=master)](https://travis-ci.org/travis-ci-examples/java-example)

# JAVA Example
Just to learn how to use travis-ci in a java project!

This is a working minimal example of how to use Travis CI with Java on GitHub.

- It uses the [JUnit](https://junit.org) testing framework
54 changes: 54 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<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>io.github.travis-ci-examples</groupId>
<artifactId>java-example</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>

<name>travis-ci-java-example</name>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>travis-ci-java-example</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>io.github.travis_ci_examples.SimpleCalculator</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>build-jar-with-dependencies</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
19 changes: 19 additions & 0 deletions src/main/java/io/github/travis_ci_examples/SimpleCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.github.travis_ci_examples;

public class SimpleCalculator {
public int add(int a, int b) {
return a + b;
}
public int sub(int a, int b) {
return a - b;
}
public int mul(int a, int b) {
return a * b;
}
public int div(int a, int b) {
return a / b;
}
public static final void main(String[] args) {
System.out.println("Hello world?");
}
}
29 changes: 29 additions & 0 deletions test/java/io/github/travis_ci_examples/SimpleCalculatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.github.travis_ci_examples;

import java.util.*;

import static org.junit.Assert.*;
import org.junit.*;

public class SimpleCalculatorTest {
@Test
public void testAdd() {
SimpleCalculator calc = new SimpleCalculator();
assertEquals(calc.add(1, 1), 2);
}
@Test
public void testSub() {
SimpleCalculator calc = new SimpleCalculator();
assertEquals(calc.sub(1, 1), 0);
}
@Test
public void testMul() {
SimpleCalculator calc = new SimpleCalculator();
assertEquals(calc.mul(3, 5), 15);
}
@Test
public void testDiv() {
SimpleCalculator calc = new SimpleCalculator();
assertEquals(calc.div(8, 2), 4);
}
}