Skip to content

Commit

Permalink
Make the builds and tests work again with updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
azabost committed Dec 30, 2023
1 parent d44662b commit 5c8a80a
Show file tree
Hide file tree
Showing 20 changed files with 161 additions and 167 deletions.
1 change: 0 additions & 1 deletion app-robo/.gitignore

This file was deleted.

17 changes: 0 additions & 17 deletions app-robo/build.gradle

This file was deleted.

34 changes: 15 additions & 19 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
plugins {
id 'com.android.library'
id 'com.github.dcendents.android-maven'
}

group='com.github.bright'

android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
namespace "pl.brightinventions.slf4android"
testNamespace "pl.brightinventions.slf4android.androidTest"

compileSdk 34

defaultConfig {
minSdkVersion 14
targetSdkVersion 28
versionCode 14
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

packagingOptions {
Expand All @@ -28,21 +27,20 @@ android {
}

dependencies {
implementation 'com.android.support:support-compat:28.0.0'
implementation 'org.slf4j:slf4j-api:1.7.7'
implementation 'androidx.core:core:1.12.0'
implementation 'org.slf4j:slf4j-api:1.7.36'
implementation 'com.squareup:seismic:1.0.2'
androidTestImplementation 'org.hamcrest:hamcrest-all:1.3'
androidTestImplementation('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
androidTestImplementation 'org.hamcrest:hamcrest-core:1.3'
androidTestImplementation 'org.hamcrest:hamcrest-library:1.3'
androidTestImplementation('junit:junit:4.13.2')
androidTestImplementation 'androidx.test:rules:1.5.0'
androidTestImplementation 'org.easytesting:fest-util:1.2.5'

testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation('junit:junit:4.11') {
exclude module: 'hamcrest-core'
}
testImplementation 'org.hamcrest:hamcrest-core:1.3'
testImplementation 'org.hamcrest:hamcrest-library:1.3'
testImplementation('junit:junit:4.13.2')
testImplementation 'org.easytesting:fest-util:1.2.5'
testImplementation('org.robolectric:robolectric:3.0') {
testImplementation('org.robolectric:robolectric:4.11.1') {
exclude module: 'classworlds'
exclude module: 'commons-logging'
exclude module: 'httpclient'
Expand All @@ -60,5 +58,3 @@ dependencies {
exclude module: 'wagon-provider-api'
}
}


8 changes: 3 additions & 5 deletions app/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<manifest
package="pl.brightinventions.slf4android"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application>
<meta-data
android:name="ignore"
android:value="ignore"/>
android:value="ignore" />

<activity android:name=".androidTest.TestActivity"/>
<activity android:name=".androidTest.TestActivity" />

<activity
android:name=".NotifyDeveloperDialogDisplayActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
package pl.brightinventions.slf4android.androidTest;

import android.test.AndroidTestCase;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;

import org.fest.util.Files;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.GregorianCalendar;

import pl.brightinventions.slf4android.FileLogHandlerConfiguration;
import pl.brightinventions.slf4android.LoggerConfiguration;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;

public class FileHandlerTests extends AndroidTestCase {
public class FileHandlerTests {
private Logger LOG;
private FileLogHandlerConfiguration handler;

@Override
protected void setUp() throws Exception {
@Before
public void setUp() {
LoggerConfiguration.resetConfigurationToDefault();
handler = LoggerConfiguration.fileLogHandler(getContext());
handler = LoggerConfiguration.fileLogHandler(getInstrumentation().getContext());
LoggerConfiguration.configuration().addHandlerToLogger(getClass().getSimpleName(), handler);
LOG = LoggerFactory.getLogger(getClass().getSimpleName());

super.setUp();
}

@Test
public void test_can_log_debug_into_file() throws Exception {
LOG.debug("Hello {}", "my friend!");

Expand All @@ -45,13 +45,14 @@ public void test_can_log_debug_into_file() throws Exception {
private String readAndClearFileEntries() throws IOException {
handler.flush();
String currentFileName = handler.getCurrentFileName();
String contents = Files.contentOf(new File(currentFileName), Charset.forName("UTF-8"));
String contents = Files.contentOf(new File(currentFileName), StandardCharsets.UTF_8);
FileChannel outChan = new FileOutputStream(currentFileName, true).getChannel();
outChan.truncate(0);
outChan.close();
return contents;
}

@Test
public void test_can_log_info_with_level_into_file() throws Exception {
LOG.info("Hello {}", "my friend!");

Expand All @@ -60,6 +61,7 @@ public void test_can_log_info_with_level_into_file() throws Exception {
assertThat(entries, containsString("INFO"));
}

@Test
public void test_can_log_warn_with_excpetion_into_file() throws Exception {
LOG.warn("Hello {}", "my friend!", new RuntimeException("A test"));

Expand All @@ -68,6 +70,7 @@ public void test_can_log_warn_with_excpetion_into_file() throws Exception {
assertThat(entries, containsString("RuntimeException"));
}

@Test
public void test_can_log_logger_name_into_file() throws Exception {
LOG.error("Hello {}", "my friend!");

Expand All @@ -76,6 +79,7 @@ public void test_can_log_logger_name_into_file() throws Exception {
assertThat(entries, containsString(LOG.getName()));
}

@Test
public void test_can_log_thread_name_into_file() throws Exception {
LOG.error("Hello {}", "my friend!");

Expand All @@ -84,6 +88,7 @@ public void test_can_log_thread_name_into_file() throws Exception {
assertThat(entries, containsString(Thread.currentThread().getName()));
}

@Test
public void test_can_log_date_into_file() throws Exception {
LOG.error("Hello {}", "my friend!");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package pl.brightinventions.slf4android.androidTest;

import android.test.AndroidTestCase;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;

import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,17 +16,12 @@
import pl.brightinventions.slf4android.LogLevel;
import pl.brightinventions.slf4android.LoggerConfiguration;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;

public class LoggerAdapterTests extends AndroidTestCase {
public class LoggerAdapterTests {

public static final String LOGGER_NAME = "ApplicationTest";

@Override
public void setUp() throws Exception {
super.setUp();
@Before
public void setUp() {
LoggerConfiguration.resetConfigurationToDefault();
clearLogcat();
}
Expand All @@ -35,7 +34,8 @@ private void clearLogcat() {
}
}

public void test_debug_message() throws Exception {
@Test
public void test_debug_message() {
getLogger().debug("Hello debug {} {}", 1, 2);
assertThat(getLastMessage(), containsString("Hello debug 1 2"));
}
Expand Down Expand Up @@ -67,31 +67,36 @@ private String getLastMessage(String tag) {
return result;
}

public void test_debug_message_multi_arg() throws Exception {
@Test
public void test_debug_message_multi_arg() {
getLogger().debug("Message {} {} {} {}", 1, 2, 3, 4);
assertThat(getLastMessage(), containsString("Message 1 2 3 4"));
}

public void test_info_message() throws Exception {
@Test
public void test_info_message() {
getLogger().info("With string '{}'", "string arg");
assertThat(getLastMessage(), containsString("With string 'string arg'"));
}

public void test_warning_message() throws Exception {
@Test
public void test_warning_message() {
getLogger().warn("warning message", new NullPointerException("Bad"));
String lastMessage = getLastMessage();
assertThat(lastMessage, containsString("warning message"));
assertThat(lastMessage, containsString(getClass().getName()));
}

public void test_error_message() throws Exception {
@Test
public void test_error_message() {
getLogger().error("error message", new IllegalArgumentException("Wrong argument"));
String lastMessage = getLastMessage();

assertThat(lastMessage, containsString("error message"));
assertThat(lastMessage, containsString("IllegalArgumentException"));
}

@Test
public void test_info_message_not_printed_when_level_is_set_to_warning() {
setLevelTo(LogLevel.WARNING);
getLogger().info("info message with exception", new NullPointerException("Bad"));
Expand All @@ -104,31 +109,36 @@ private void setLevelTo(LogLevel level) {
configuration.setRootLogLevel(level);
}

@Test
public void test_debug_message_not_printed_when_level_is_set_to_info() {
setLevelTo(LogLevel.INFO);
getLogger().debug("debug message with exception", new NullPointerException("Bad"));
assertThat(getLastMessage(), not(containsString("debug message with exception")));
}

@Test
public void test_trace_message_not_printed_when_level_is_set_to_info() {
setLevelTo(LogLevel.INFO);
getLogger().trace("new trace message with exception", new NullPointerException("Bad"));
assertThat(getLastMessage(), not(containsString("new trace message with exception")));
}

@Test
public void test_trace_message_not_printed_when_level_is_set_to_debug() {
setLevelTo(LogLevel.DEBUG);
getLogger().trace("trace message with exception", new NullPointerException("Bad"));
String lastMessage = getLastMessage();
assertThat(lastMessage, not(containsString("trace message with exception")));
}

@Test
public void test_error_message_printed_when_level_is_set_to_debug() {
setLevelTo(LogLevel.DEBUG);
getLogger().error("error message with exception", new NullPointerException("Bad"));
assertThat(getLastMessage(), containsString("error message with exception"));
}

@Test
public void test_warning_message_printed_when_level_is_set_to_debug() {
setLevelTo(LogLevel.DEBUG);
getLogger().error("new warning message with exception", new NullPointerException("Bad"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package pl.brightinventions.slf4android.androidTest;

import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import android.app.Application;
import android.test.ActivityInstrumentationTestCase2;

import androidx.test.rule.ActivityTestRule;

import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -11,7 +16,7 @@
import pl.brightinventions.slf4android.LoggerConfiguration;
import pl.brightinventions.slf4android.NotifyDeveloperHandler;

public class NotifyDeveloperHandlerTests extends ActivityInstrumentationTestCase2<TestActivity> {
public class NotifyDeveloperHandlerTests extends ActivityTestRule<TestActivity> {

private Logger LOG;
private NotifyDeveloperHandler handler;
Expand All @@ -20,30 +25,32 @@ public NotifyDeveloperHandlerTests() {
super(TestActivity.class);
}

@Override
protected void setUp() throws Exception {
@Before
public void setUp() {
LoggerConfiguration.resetConfigurationToDefault();
LoggerConfiguration configuration = LoggerConfiguration.configuration();
Application targetContext = (Application) getInstrumentation().getTargetContext().getApplicationContext();
handler = configuration.notifyDeveloperHandler(targetContext, "[email protected]");
configuration.addHandlerToLogger("", handler);
LOG = LoggerFactory.getLogger(getClass().getSimpleName());
super.setUp();
}

public void test_dont_send_message_with_level_lower_than_error() throws Exception {
@Test
public void test_dont_send_message_with_level_lower_than_error() {
getActivity();
LOG.warn("Hello");
}

@Test
public void test_send_message_with_level_error() throws Exception {
getActivity();
LOG.warn("Hello");
LOG.error("Send email", new NullPointerException("A test message"));
Thread.sleep(TimeUnit.SECONDS.toMillis(15));
}

public void test_send_message_with_custom_subject_body_with_level_error() throws Exception{
@Test
public void test_send_message_with_custom_subject_body_with_level_error() throws Exception {
handler.withSubject("Błąd").withBody("Podaj szczegóły błędu: ");
getActivity();
LOG.warn("Hello");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(pl.brightinventions.slf4android.test.R.layout.test);
setContentView(R.layout.test);
}
}
Loading

0 comments on commit 5c8a80a

Please sign in to comment.