-
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
1 parent
6a38253
commit 209a288
Showing
11 changed files
with
239 additions
and
124 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
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
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
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,17 @@ | ||
package mina.core; | ||
|
||
public class DoNothingCheck implements MinaCheck { | ||
private static final MinaCheck INSTANCE = new DoNothingCheck(); | ||
|
||
private DoNothingCheck() { | ||
} | ||
|
||
public static MinaCheck getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public void verify(int index, Object[] arguments, Throwable throwable) { | ||
// Do nothing | ||
} | ||
} |
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,145 @@ | ||
package mina.core; | ||
|
||
|
||
import mina.subject.EmptyCode; | ||
import mina.subject.Simple; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static mina.core.Mina.assertAllCalled; | ||
import static mina.core.Mina.on; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.slf4j.event.Level.*; | ||
|
||
public class MinaTest { | ||
@AfterEach | ||
public void clean() { | ||
Mina.clean(); | ||
} | ||
|
||
@Test | ||
public void testDoNothing() { | ||
on(EmptyCode.class, INFO, "Log something: {}") | ||
.checkArguments(arguments -> assertEquals(3, arguments.length)); | ||
|
||
new EmptyCode().doNothing(); | ||
|
||
assertThrows(AssertionError.class, Mina::assertAllCalled); | ||
} | ||
|
||
@Test | ||
public void testSomething() { | ||
on(Simple.class, TRACE, "Trace something").check(); | ||
on(Simple.class, DEBUG, Simple.TEST_MARKER, "Debug something").check(); | ||
on(Simple.class, INFO, "This is a {} log").check(3); | ||
on(Simple.class, WARN, "Warn {}").check((String problem, Throwable throwable) -> { | ||
assertEquals("problem", problem); | ||
assertInstanceOf(Exception.class, throwable); | ||
}); | ||
on(Simple.class, ERROR, "Test error") | ||
.check((Throwable throwable) -> assertInstanceOf(RuntimeException.class, throwable)); | ||
|
||
new Simple().doSomething(); | ||
|
||
assertAllCalled(); | ||
} | ||
|
||
@Test | ||
public void testOnlyLoggerCondition() { | ||
on(Simple.class).check(); | ||
new Simple().doSingleLog(); | ||
assertAllCalled(); | ||
} | ||
|
||
@Test | ||
public void testOnlyLevelCondition() { | ||
on(INFO).check(); | ||
new Simple().doSingleLog(); | ||
assertAllCalled(); | ||
} | ||
|
||
@Test | ||
public void testLoggerLevelCondition() { | ||
on(Simple.class, INFO).check(); | ||
new Simple().doSingleLog(); | ||
assertAllCalled(); | ||
} | ||
|
||
@Test | ||
public void testNoCondition() { | ||
on().check(); | ||
new Simple().doSingleLog(); | ||
assertAllCalled(); | ||
} | ||
|
||
@Test | ||
public void testPartialCondition() { | ||
on(Simple.class, DEBUG, Simple.MARKER_1).check(1); | ||
on(Simple.class, Simple.MARKER_2, "message 2 {}").check(2); | ||
on(Simple.class, Simple.MARKER_3).check(3); | ||
on(Simple.class, "message 4 {}").check(4); | ||
on(INFO, Simple.MARKER_1, "message 5 {}").check(5); | ||
on(INFO, Simple.MARKER_2).check(6); | ||
on(INFO, "message 7 {}").check(7); | ||
on(Simple.MARKER_1, "message 8 {}").check(8); | ||
on(Simple.TEST_MARKER).check(9); | ||
on("message 10 {}").check(10); | ||
|
||
new Simple().doConditions(); | ||
assertAllCalled(); | ||
} | ||
|
||
@Test | ||
public void testIndex() { | ||
AtomicInteger count = new AtomicInteger(); | ||
on(Simple.class).checkCanonical((index, arguments, throwable) -> assertEquals(count.incrementAndGet(), index)); | ||
|
||
new Simple().doSomething(); | ||
|
||
assertAllCalled(); | ||
} | ||
|
||
@Test | ||
public void testPartialLoggerName() { | ||
on("mina.subject", INFO, null, null).check(); | ||
|
||
new Simple().doSomething(); | ||
|
||
assertAllCalled(); | ||
} | ||
|
||
@Test | ||
public void testException() { | ||
on(ERROR) | ||
.checkThrowable((throwable) -> assertInstanceOf(RuntimeException.class, throwable)); | ||
|
||
new Simple().doException(); | ||
|
||
assertAllCalled(); | ||
} | ||
|
||
@Test | ||
public void testExceptionWithArguments() { | ||
on(ERROR) | ||
.checkArguments((arguments, throwable) -> { | ||
assertInstanceOf(RuntimeException.class, throwable); | ||
assertEquals("Vitalii", arguments[0]); | ||
assertNull(arguments[1]); | ||
}); | ||
|
||
new Simple().doException(); | ||
|
||
assertAllCalled(); | ||
} | ||
|
||
@Test | ||
public void testForbidden() { | ||
on(ERROR).exception(); | ||
|
||
assertThrows(AssertionError.class, () -> new Simple().doException()); | ||
|
||
assertAllCalled(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...est/java/mina/test/QuadraticEquation.java → .../java/mina/example/QuadraticEquation.java
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package mina.test; | ||
package mina.example; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
2 changes: 1 addition & 1 deletion
2
...java/mina/test/QuadraticEquationTest.java → ...a/mina/example/QuadraticEquationTest.java
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package mina.test; | ||
package mina.example; | ||
|
||
import mina.core.Mina; | ||
import org.junit.jupiter.api.AfterEach; | ||
|
2 changes: 1 addition & 1 deletion
2
src/test/java/mina/test/EmptyCode.java → src/test/java/mina/subject/EmptyCode.java
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package mina.test; | ||
package mina.subject; | ||
|
||
public class EmptyCode { | ||
public void doNothing() { | ||
|
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,67 @@ | ||
package mina.subject; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.slf4j.Marker; | ||
import org.slf4j.MarkerFactory; | ||
|
||
public class Simple { | ||
private final Logger log = LoggerFactory.getLogger(Simple.class); | ||
public static final Marker TEST_MARKER = MarkerFactory.getMarker("TEST"); | ||
|
||
public static final Marker MARKER_1 = MarkerFactory.getMarker("MARKER_1"); | ||
public static final Marker MARKER_2 = MarkerFactory.getMarker("MARKER_2"); | ||
public static final Marker MARKER_3 = MarkerFactory.getMarker("MARKER_3"); | ||
|
||
public void doSomething() { | ||
log.trace("Trace something"); | ||
log.debug(TEST_MARKER, "Debug something"); | ||
log.info("This is a {} log", 3); | ||
log.warn("Warn {}", "problem", new Exception("Test exception")); | ||
log.error("Test error", new RuntimeException("Test runtime exception")); | ||
} | ||
|
||
public void doSingleLog() { | ||
log.info("message"); | ||
} | ||
|
||
public void doConditions() { | ||
// Logger, level, marker | ||
log.debug(MARKER_1, "message 1 {}", 1); | ||
|
||
// Logger, marker, message | ||
log.debug(MARKER_2, "message 2 {}", 2); | ||
|
||
// Logger marker | ||
log.debug(MARKER_3, "message 3 {}", 3); | ||
|
||
// Logger, message | ||
log.debug("message 4 {}", 4); | ||
|
||
// Level, marker, message | ||
log.info(MARKER_1, "message 5 {}", 5); | ||
|
||
// Level, marker | ||
log.info(MARKER_2, "message 6 {}", 6); | ||
|
||
// Level message | ||
log.info("message 7 {}", 7); | ||
|
||
// Marker, message | ||
log.warn(MARKER_1, "message 8 {}", 8); | ||
|
||
// Just marker | ||
log.warn(TEST_MARKER, "message 9 {}", 9); | ||
|
||
// Just message | ||
log.warn("message 10 {}", 10); | ||
} | ||
|
||
public void doException() { | ||
try { | ||
throw new RuntimeException("Test exception"); | ||
} catch (Exception e) { | ||
log.error("Test error (c) {} {} {}", "Vitalii", null, "Samolovskikh", e); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.