diff options
Diffstat (limited to 'java/project/src')
-rw-r--r-- | java/project/src/main/ch/asynk/Main.java | 22 | ||||
-rw-r--r-- | java/project/src/main/ch/asynk/MyClass.java | 25 | ||||
-rw-r--r-- | java/project/src/main/ch/asynk/MyException.java | 11 | ||||
-rw-r--r-- | java/project/src/resources/Application.properties | 3 | ||||
-rw-r--r-- | java/project/src/resources/logback-test.xml | 34 | ||||
-rw-r--r-- | java/project/src/test/java/ch/asynk/Test00.java | 54 | ||||
-rw-r--r-- | java/project/src/test/java/ch/asynk/TestSuite.java | 27 |
7 files changed, 176 insertions, 0 deletions
diff --git a/java/project/src/main/ch/asynk/Main.java b/java/project/src/main/ch/asynk/Main.java new file mode 100644 index 0000000..bb187bf --- /dev/null +++ b/java/project/src/main/ch/asynk/Main.java @@ -0,0 +1,22 @@ +package ch.asynk; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Main +{ + private static Logger logger = null; + + public static void main(String [] args ) + { + logger = LoggerFactory.getLogger(Main.class); + System.out.println("System.out"); + System.err.println("System.err"); + logger.trace("trace"); + logger.debug("debug"); + logger.info("info"); + logger.warn("warn"); + logger.error("error"); + System.exit(0); + } +} diff --git a/java/project/src/main/ch/asynk/MyClass.java b/java/project/src/main/ch/asynk/MyClass.java new file mode 100644 index 0000000..57ef46f --- /dev/null +++ b/java/project/src/main/ch/asynk/MyClass.java @@ -0,0 +1,25 @@ +package ch.asynk; + +import lombok.Getter; + +public class MyClass +{ + static private String msg = "Hello World"; + + private @Getter int n; + + public MyClass() + { + n = 666; + } + + public void print() + { + System.err.println(msg); + } + + public void exception() throws MyException + { + throw new MyException("it's mine"); + } +} diff --git a/java/project/src/main/ch/asynk/MyException.java b/java/project/src/main/ch/asynk/MyException.java new file mode 100644 index 0000000..06203ae --- /dev/null +++ b/java/project/src/main/ch/asynk/MyException.java @@ -0,0 +1,11 @@ +package ch.asynk; + +public class MyException extends Exception +{ + private static final long serialVersionUID = 01235; + + public MyException(String message) + { + super(message); + } +} diff --git a/java/project/src/resources/Application.properties b/java/project/src/resources/Application.properties new file mode 100644 index 0000000..34430cd --- /dev/null +++ b/java/project/src/resources/Application.properties @@ -0,0 +1,3 @@ +app.logfile=MyApp.log +app.version=0.0.1 +app.env=DEV diff --git a/java/project/src/resources/logback-test.xml b/java/project/src/resources/logback-test.xml new file mode 100644 index 0000000..7f49e52 --- /dev/null +++ b/java/project/src/resources/logback-test.xml @@ -0,0 +1,34 @@ +<configuration debug="true"> + + <contextName>MyApp</contextName> + <property resource="Application.properties" /> + <property name="LOG_LEVEL" value="INFO" /> + <property name="LOG_REF" value="FILE" /> + <property name="LOG_FILE" value="${app.logfile}" /> + <property name="LOG_PATTERN" value="%contextName %date{ISO8601} [%-5level %thread] [%file:%line] - %msg%n" /> + + <if condition='property("app.env").contains("DEV")'> + <then> + <property name="LOG_LEVEL" value="DEBUG" /> + <property name="LOG_REF" value="STDOUT" /> + </then> + </if> + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>${LOG_PATTERN}</pattern> + </encoder> + </appender> + + <appender name="FILE" class="ch.qos.logback.core.FileAppender"> + <file>${LOG_FILE}</file> + <encoder> + <pattern>${LOG_PATTERN}</pattern> + </encoder> + </appender> + + <root level="${LOG_LEVEL}"> + <appender-ref ref="${LOG_REF}" /> + </root> + +</configuration> diff --git a/java/project/src/test/java/ch/asynk/Test00.java b/java/project/src/test/java/ch/asynk/Test00.java new file mode 100644 index 0000000..aae83d7 --- /dev/null +++ b/java/project/src/test/java/ch/asynk/Test00.java @@ -0,0 +1,54 @@ +package ch.asynk; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.rules.ExpectedException; + +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.hasProperty; + +import ch.asynk.MyClass; + +public class Test00 +{ + private static MyClass my; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @BeforeClass + public static void setUpClass() + { + System.out.println(" BeforeClass : Test00"); + my = new MyClass(); + } + + @AfterClass + public static void tearDownClass() + { + System.out.println(" AfterClass : Test00"); + } + + @Test + public void test_0() + { + assertEquals("n must be equal to 666", my.getN(), 666); + } + + @Test + public void test_1() throws MyException + { + thrown.expect(MyException.class); + thrown.expectMessage("it's mine"); + my.exception(); + } + @Test + public void test_2() throws MyException + { + assertThat(my, hasProperty("n", is(666))); + } +} diff --git a/java/project/src/test/java/ch/asynk/TestSuite.java b/java/project/src/test/java/ch/asynk/TestSuite.java new file mode 100644 index 0000000..3e5d7d8 --- /dev/null +++ b/java/project/src/test/java/ch/asynk/TestSuite.java @@ -0,0 +1,27 @@ +package ch.asynk; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.junit.BeforeClass; +import org.junit.AfterClass; + +@RunWith(Suite.class) + +@Suite.SuiteClasses({ + Test00.class +}) + +public class TestSuite +{ + @BeforeClass + public static void setUpClass() + { + System.out.println("BeforeClass : TestSuite"); + } + + @AfterClass + public static void tearDownClass() + { + System.out.println("AfterClass : TestSuite"); + } +} |