Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
orhanobut committed Aug 2, 2015
1 parent 0cd51f5 commit 022e977
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 148 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
# org.gradle.parallel=true

#VERSION_NAME=1.0-SNAPSHOT
VERSION_NAME=1.10
VERSION_CODE=11
VERSION_NAME=1.11
VERSION_CODE=12
GROUP=com.orhanobut

POM_DESCRIPTION=Simple,pretty and powerful log
Expand Down
7 changes: 7 additions & 0 deletions logger/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ android {
}
}

dependencies {
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
testCompile "org.robolectric:robolectric:3.0"
testCompile 'org.assertj:assertj-core:1.7.0'
}

apply from: '../maven_push.gradle'
98 changes: 0 additions & 98 deletions logger/src/androidTest/java/com/orhanobut/logger/LoggerTest.java

This file was deleted.

5 changes: 1 addition & 4 deletions logger/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.orhanobut.logger">

<application android:allowBackup="true"/>
<manifest package="com.orhanobut.logger">

</manifest>
91 changes: 47 additions & 44 deletions logger/src/main/java/com/orhanobut/logger/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,51 @@
*/
public final class Settings {

private int methodCount = 2;
private boolean showThreadInfo = true;
private int methodOffset = 0;

/**
* Determines how logs will printed
*/
private LogLevel logLevel = LogLevel.FULL;

public Settings hideThreadInfo() {
showThreadInfo = false;
return this;
}

public Settings setMethodCount(int methodCount) {
this.methodCount = methodCount;
return this;
}

public Settings setLogLevel(LogLevel logLevel) {
this.logLevel = logLevel;
return this;
}

public Settings setMethodOffset(int offset) {
this.methodOffset = offset;
return this;
}

public int getMethodCount() {
return methodCount;
}

public boolean isShowThreadInfo() {
return showThreadInfo;
}

public LogLevel getLogLevel() {
return logLevel;
}

public int getMethodOffset() {
return methodOffset;
}
private int methodCount = 2;
private boolean showThreadInfo = true;
private int methodOffset = 0;

/**
* Determines how logs will printed
*/
private LogLevel logLevel = LogLevel.FULL;

public Settings hideThreadInfo() {
showThreadInfo = false;
return this;
}

public Settings setMethodCount(int methodCount) {
if (methodCount < 0) {
methodCount = 0;
}
this.methodCount = methodCount;
return this;
}

public Settings setLogLevel(LogLevel logLevel) {
this.logLevel = logLevel;
return this;
}

public Settings setMethodOffset(int offset) {
this.methodOffset = offset;
return this;
}

public int getMethodCount() {
return methodCount;
}

public boolean isShowThreadInfo() {
return showThreadInfo;
}

public LogLevel getLogLevel() {
return logLevel;
}

public int getMethodOffset() {
return methodOffset;
}
}
43 changes: 43 additions & 0 deletions logger/src/test/java/com.orhanobut.logger/LoggerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.orhanobut.logger;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Orhan Obut
*/
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class LoggerTest {

@Test
public void testInit() {
Settings settings = Logger.init();
assertThat(settings).isInstanceOf(Settings.class);

settings = Logger.init("TAG");
assertThat(settings).isInstanceOf(Settings.class);
}

@Test
public void testT() {
Settings settings = Logger.t("tag").getSettings();

assertThat(settings.getMethodCount()).isEqualTo(2);

settings = Logger.t(10).getSettings();
assertThat(settings.getMethodCount()).isEqualTo(2);

settings = Logger.t("tag", 5).getSettings();
assertThat(settings.getMethodCount()).isEqualTo(2);

Logger.init().setMethodCount(0);
settings = Logger.t("tag").getSettings();
assertThat(settings.getMethodCount()).isEqualTo(0);
}

}
82 changes: 82 additions & 0 deletions logger/src/test/java/com.orhanobut.logger/SettingsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.orhanobut.logger;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricGradleTestRunner;
import org.robolectric.annotation.Config;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Orhan Obut
*/
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class SettingsTest extends TestCase {

private Settings settings;

@Before
public void setup() {
settings = new Settings();
}

@After
public void tearDown() {
settings = null;
}

@Test
public void testDefaultShowThreadInfo() {
assertThat(settings.isShowThreadInfo()).isTrue();
}

@Test
public void testCustomShowThreadInfo() {
settings.hideThreadInfo();
assertThat(settings.isShowThreadInfo()).isFalse();
}

@Test
public void testDefaultLogLevel() {
assertThat(settings.getLogLevel()).isEqualTo(LogLevel.FULL);
}

@Test
public void testCustomLogLevel() {
settings.setLogLevel(LogLevel.NONE);
assertThat(settings.getLogLevel()).isEqualTo(LogLevel.NONE);

settings.setLogLevel(LogLevel.FULL);
assertThat(settings.getLogLevel()).isEqualTo(LogLevel.FULL);
}

@Test
public void testMethodCount() {
//default
assertThat(settings.getMethodCount()).isEqualTo(2);

settings.setMethodCount(4);
assertThat(settings.getMethodCount()).isEqualTo(4);

//negative values should be convert to 0
settings.setMethodCount(-10);
assertThat(settings.getMethodCount()).isEqualTo(0);
}

@Test
public void testMethodOffset() {
//default
assertThat(settings.getMethodOffset()).isEqualTo(0);

settings.setMethodOffset(10);
assertThat(settings.getMethodOffset()).isEqualTo(10);

settings.setMethodOffset(-10);
assertThat(settings.getMethodOffset()).isEqualTo(-10);
}
}

0 comments on commit 022e977

Please sign in to comment.