-
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.
[Feature] New method setLogLevel & getLogger for CompositeLogger
- Loading branch information
Showing
3 changed files
with
85 additions
and
1 deletion.
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
54 changes: 54 additions & 0 deletions
54
logger/src/test/java/m/co/rh/id/alogger/CompositeLoggerTest.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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package m.co.rh.id.alogger; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CompositeLoggerTest { | ||
|
||
@Test | ||
public void getLogger_gettingExactLoggerType() { | ||
AndroidLogger androidLogger = Mockito.mock(AndroidLogger.class); | ||
FileLogger fileLogger = Mockito.mock(FileLogger.class); | ||
ToastLogger toastLogger = Mockito.mock(ToastLogger.class); | ||
List<ILogger> iLoggerList = new ArrayList<>(); | ||
iLoggerList.add(androidLogger); | ||
iLoggerList.add(fileLogger); | ||
iLoggerList.add(toastLogger); | ||
|
||
CompositeLogger compositeLogger = new CompositeLogger(iLoggerList); | ||
Assert.assertSame(compositeLogger.getLogger(AndroidLogger.class), androidLogger); | ||
Assert.assertSame(compositeLogger.getLogger(FileLogger.class), fileLogger); | ||
Assert.assertSame(compositeLogger.getLogger(ToastLogger.class), toastLogger); | ||
} | ||
|
||
@Test | ||
public void setLogLevel_settingBaseOnLoggerType() { | ||
AndroidLogger androidLogger = Mockito.mock(AndroidLogger.class); | ||
FileLogger fileLogger = Mockito.mock(FileLogger.class); | ||
ToastLogger toastLogger = Mockito.mock(ToastLogger.class); | ||
List<ILogger> iLoggerList = new ArrayList<>(); | ||
iLoggerList.add(androidLogger); | ||
iLoggerList.add(fileLogger); | ||
iLoggerList.add(toastLogger); | ||
|
||
CompositeLogger compositeLogger = new CompositeLogger(iLoggerList); | ||
compositeLogger.setLogLevel(AndroidLogger.class, ILogger.ERROR); | ||
Mockito.verify(androidLogger, Mockito.times(1)).setLogLevel(ILogger.ERROR); | ||
compositeLogger.setLogLevel(FileLogger.class, ILogger.DEBUG); | ||
Mockito.verify(fileLogger, Mockito.times(1)).setLogLevel(ILogger.DEBUG); | ||
compositeLogger.setLogLevel(ToastLogger.class, ILogger.INFO); | ||
Mockito.verify(toastLogger, Mockito.times(1)).setLogLevel(ILogger.INFO); | ||
|
||
Mockito.clearInvocations(androidLogger, fileLogger, toastLogger); | ||
|
||
compositeLogger.setLogLevel(ILogger.class, ILogger.VERBOSE); | ||
Mockito.verify(androidLogger, Mockito.times(1)).setLogLevel(ILogger.VERBOSE); | ||
Mockito.verify(fileLogger, Mockito.times(1)).setLogLevel(ILogger.VERBOSE); | ||
Mockito.verify(toastLogger, Mockito.times(1)).setLogLevel(ILogger.VERBOSE); | ||
|
||
} | ||
} |