Skip to content

Commit

Permalink
Test caller line data only when available
Browse files Browse the repository at this point in the history
This data is not available in app release builds.
  • Loading branch information
tony19 committed Sep 15, 2018
1 parent e81b46d commit 9fdef77
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
import ch.qos.logback.core.pattern.DynamicConverter;
import ch.qos.logback.core.pattern.FormatInfo;

import static org.junit.Assume.assumeThat;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.Matchers.greaterThan;

public class ConverterTest {

Expand Down Expand Up @@ -68,13 +70,12 @@ public void setUp() throws Exception {

@Test
public void testLineOfCaller() {
{
DynamicConverter<ILoggingEvent> converter = new LineOfCallerConverter();
StringBuilder buf = new StringBuilder();
converter.write(buf, le);
// the number below should be the line number of the previous line
assertEquals("74", buf.toString());
}
assumeStackTraceDetailsAvailable();
DynamicConverter<ILoggingEvent> converter = new LineOfCallerConverter();
StringBuilder buf = new StringBuilder();
converter.write(buf, le);
// the number below should be the line number of the previous line
assertEquals("76", buf.toString());
}

@Test
Expand Down Expand Up @@ -218,6 +219,7 @@ public void testMethodOfCaller() {

@Test
public void testFileOfCaller() {
assumeStackTraceDetailsAvailable();
DynamicConverter<ILoggingEvent> converter = new FileOfCallerConverter();
StringBuilder buf = new StringBuilder();
converter.write(buf, le);
Expand Down Expand Up @@ -401,4 +403,9 @@ public void contextProperty() {
String result = converter.convert(event);
assertEquals("v", result);
}

private void assumeStackTraceDetailsAvailable() {
StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
assumeThat(stackTraceElements[0].getLineNumber(), is(greaterThan(-1)));
}
}

0 comments on commit 9fdef77

Please sign in to comment.