Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove guava dependency (actualized) #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>

<artifactId>lidalia-slf4j-ext</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.0</version>

<name>Lidalia Extensions to SLF4J</name>
<description>A wrapper for an SLF4J Logger that includes methods allowing logging to
Expand Down Expand Up @@ -40,10 +40,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>standard-test-dependencies</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/uk/org/lidalia/slf4jext/ConvenientLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import org.slf4j.Marker;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;
import static uk.org.lidalia.slf4jext.Level.DEBUG;
import static uk.org.lidalia.slf4jext.Level.ERROR;
import static uk.org.lidalia.slf4jext.Level.INFO;
Expand All @@ -24,7 +24,7 @@ public ConvenientLogger(final LightestLogger decorated) {
}

public ConvenientLogger(final LightLogger decorated) {
this.decorated = checkNotNull(decorated);
this.decorated = requireNonNull(decorated);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package uk.org.lidalia.slf4jext;

import com.google.common.collect.ImmutableSet;

import static com.google.common.collect.Sets.immutableEnumSet;
import static uk.org.lidalia.slf4jext.Level.DEBUG;
import static uk.org.lidalia.slf4jext.Level.ERROR;
import static uk.org.lidalia.slf4jext.Level.INFO;
import static uk.org.lidalia.slf4jext.Level.TRACE;
import static uk.org.lidalia.slf4jext.Level.WARN;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

/**
* The conventional hierarchical notion of Levels, where info being enabled implies warn and error being enabled, is not a
* requirement of the SLF4J API. These constants are a shortcut if you wish to use traditional hierarchical setups.
Expand All @@ -20,42 +21,42 @@ public final class ConventionalLevelHierarchy {
*
* An empty set.
*/
public static final ImmutableSet<Level> OFF_LEVELS = ImmutableSet.of();
public static final Set<Level> OFF_LEVELS = Collections.emptySet();

/**
* Levels that would be considered enabled in Log4J/Logback if a Logger was set to ERROR.
*
* A set containing {@link Level#ERROR}.
*/
public static final ImmutableSet<Level> ERROR_LEVELS = immutableEnumSet(ERROR);
public static final Set<Level> ERROR_LEVELS = Collections.unmodifiableSet(EnumSet.of(ERROR));

/**
* Levels that would be considered enabled in Log4J/Logback if a Logger was set to WARN.
*
* A set containing {@link Level#ERROR} and {@link Level#WARN}.
*/
public static final ImmutableSet<Level> WARN_LEVELS = immutableEnumSet(ERROR, WARN);
public static final Set<Level> WARN_LEVELS = Collections.unmodifiableSet(EnumSet.of(ERROR, WARN));

/**
* Levels that would be considered enabled in Log4J/Logback if a Logger was set to INFO.
*
* A set containing {@link Level#ERROR}, {@link Level#WARN} and {@link Level#INFO}.
*/
public static final ImmutableSet<Level> INFO_LEVELS = immutableEnumSet(ERROR, WARN, INFO);
public static final Set<Level> INFO_LEVELS = Collections.unmodifiableSet(EnumSet.of(ERROR, WARN, INFO));

/**
* Levels that would be considered enabled in Log4J/Logback if a Logger was set to DEBUG.
*
* A set containing {@link Level#ERROR}, {@link Level#WARN}, {@link Level#INFO} and {@link Level#DEBUG}.
*/
public static final ImmutableSet<Level> DEBUG_LEVELS = immutableEnumSet(ERROR, WARN, INFO, DEBUG);
public static final Set<Level> DEBUG_LEVELS = Collections.unmodifiableSet(EnumSet.of(ERROR, WARN, INFO, DEBUG));

/**
* Levels that would be considered enabled in Log4J/Logback if a Logger was set to TRACE.
*
* A set containing {@link Level#ERROR}, {@link Level#WARN}, {@link Level#INFO}, {@link Level#DEBUG} and {@link Level#TRACE}.
*/
public static final ImmutableSet<Level> TRACE_LEVELS = immutableEnumSet(ERROR, WARN, INFO, DEBUG, TRACE);
public static final Set<Level> TRACE_LEVELS = Collections.unmodifiableSet(EnumSet.of(ERROR, WARN, INFO, DEBUG, TRACE));

private ConventionalLevelHierarchy() {
throw new UnsupportedOperationException("Not instantiable");
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/uk/org/lidalia/slf4jext/DefaultLightLogger.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package uk.org.lidalia.slf4jext;

import org.slf4j.Marker;
import static java.util.Objects.requireNonNull;

import static com.google.common.base.Preconditions.checkNotNull;
import org.slf4j.Marker;

public class DefaultLightLogger implements LightLogger {

Expand All @@ -16,7 +16,7 @@ public class DefaultLightLogger implements LightLogger {
* @param decorated the SLF4J {@link org.slf4j.Logger} to which all logging calls will be delegated
*/
public DefaultLightLogger(final org.slf4j.Logger decorated) {
this.decorated = checkNotNull(decorated);
this.decorated = requireNonNull(decorated);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

import org.slf4j.Marker;

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Objects.requireNonNull;

public class DefaultLightestLogger implements LightestLogger {

private final org.slf4j.Logger logger;

public DefaultLightestLogger(org.slf4j.Logger logger) {
this.logger = checkNotNull(logger);
this.logger = requireNonNull(logger);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/uk/org/lidalia/slf4jext/DefaultLogger.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package uk.org.lidalia.slf4jext;

import org.slf4j.Marker;
import static java.util.Objects.requireNonNull;

import static com.google.common.base.Preconditions.checkNotNull;
import org.slf4j.Marker;

/**
* A decorator around an SLF4J {@link org.slf4j.Logger} that adds a set of methods called log that take an instance of Level as
Expand All @@ -29,7 +29,7 @@ public DefaultLogger(final org.slf4j.Logger decorated) {

public DefaultLogger(final LightLogger decorated) {
super(decorated);
this.decorated = checkNotNull(decorated);
this.decorated = requireNonNull(decorated);
}

public DefaultLogger(final LightestLogger decorated) {
Expand Down
27 changes: 12 additions & 15 deletions src/main/java/uk/org/lidalia/slf4jext/Level.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package uk.org.lidalia.slf4jext;

import com.google.common.collect.ImmutableSet;
import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.Marker;

import java.util.HashSet;

import static com.google.common.collect.Sets.immutableEnumSet;
import static com.google.common.collect.Sets.newHashSet;
import static java.util.Arrays.asList;

/**
* Enum modelling the logical levels implied by the way <a href="http://www.slf4j.org">SLF4J</a> has the same set of methods
* repeated with different names.
Expand Down Expand Up @@ -321,8 +318,8 @@ void log(final Logger logger, final Marker marker, final String message, final T
}
};

private static final ImmutableSet<Level> ALL_LEVELS = immutableEnumSet(asList(values()));
private static final ImmutableSet<Level> ENABLABLE_LEVELS = makeEnablabeValues();
private static final Set<Level> ALL_LEVELS = Collections.unmodifiableSet(EnumSet.allOf(Level.class));
private static final Set<Level> ENABLABLE_LEVELS = Collections.unmodifiableSet(makeEnablabeValues());

abstract boolean isEnabled(Logger logger);

Expand Down Expand Up @@ -351,20 +348,20 @@ void log(final Logger logger, final Marker marker, final String message, final T
/**
* @return an ImmutableSet containing the constants of this enum type
*/
public static ImmutableSet<Level> valueSet() {
public static Set<Level> valueSet() {
return ALL_LEVELS;
}

/**
* @return an ImmutableSet containing the constants of this enum type other than OFF
*/
public static ImmutableSet<Level> enablableValueSet() {
public static Set<Level> enablableValueSet() {
return ENABLABLE_LEVELS;
}

private static ImmutableSet<Level> makeEnablabeValues() {
final HashSet<Level> levels = newHashSet(values());
levels.remove(OFF);
return immutableEnumSet(levels);
private static Set<Level> makeEnablabeValues() {
EnumSet<Level> enabled = EnumSet.allOf(Level.class);
enabled.remove(OFF);
return enabled;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package uk.org.lidalia.slf4jext;

import org.slf4j.Marker;
import static java.util.Objects.requireNonNull;

import static com.google.common.base.Preconditions.checkNotNull;
import org.slf4j.Marker;

public class LightestLoggerToLightLoggerAdapter implements LightLogger {

private final LightestLogger decorated;

public LightestLoggerToLightLoggerAdapter(LightestLogger decorated) {
this.decorated = checkNotNull(decorated);
this.decorated = requireNonNull(decorated);
}

@Override
Expand Down
20 changes: 9 additions & 11 deletions src/test/java/uk/org/lidalia/slf4jutils/LevelTests.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package uk.org.lidalia.slf4jutils;

import java.util.Set;

import org.junit.Test;

import com.google.common.collect.ImmutableSet;

import uk.org.lidalia.slf4jext.Level;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static uk.org.lidalia.slf4jext.Level.DEBUG;
import static uk.org.lidalia.slf4jext.Level.ERROR;
import static uk.org.lidalia.slf4jext.Level.INFO;
import static uk.org.lidalia.slf4jext.Level.TRACE;
import static uk.org.lidalia.slf4jext.Level.WARN;

import java.util.EnumSet;
import java.util.Set;

import org.junit.Test;

import uk.org.lidalia.slf4jext.Level;

public class LevelTests {

@Test
Expand All @@ -32,7 +30,7 @@ public void valueSetIsImmutable() {

@Test
public void enablableValueSetContains() {
assertThat(Level.enablableValueSet(), is(ImmutableSet.of(ERROR, WARN, INFO, DEBUG, TRACE)));
assertTrue(Level.enablableValueSet().equals(EnumSet.of(ERROR, WARN, INFO, DEBUG, TRACE)));
}

@Test(expected = UnsupportedOperationException.class)
Expand Down
40 changes: 17 additions & 23 deletions src/test/java/uk/org/lidalia/slf4jutils/LoggerTests.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
package uk.org.lidalia.slf4jutils;

import com.google.common.base.Function;
import com.google.common.collect.Lists;
import junitparams.JUnitParamsRunner;
import junitparams.Parameters;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Marker;

import java.lang.reflect.Method;
import java.util.List;

import uk.org.lidalia.slf4jext.DefaultLogger;
import uk.org.lidalia.slf4jext.Logger;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.powermock.api.mockito.PowerMockito.mock;
Expand All @@ -32,6 +15,18 @@
import static uk.org.lidalia.slf4jext.Level.WARN;
import static uk.org.lidalia.test.Values.uniqueValueFor;

import java.lang.reflect.Method;

import junitparams.JUnitParamsRunner;
import junitparams.Parameters;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Marker;

import uk.org.lidalia.slf4jext.DefaultLogger;
import uk.org.lidalia.slf4jext.Logger;

@RunWith(JUnitParamsRunner.class)
public class LoggerTests {

Expand Down Expand Up @@ -586,11 +581,10 @@ public void errorMarkerMessageVarArgs() {

private Object[] buildParamsFor(Method loggerMethod) throws Exception {
Class<?>[] parameterTypes = loggerMethod.getParameterTypes();
List<Object> params = Lists.transform(asList(parameterTypes), new Function<Class<?>, Object>() {
public Object apply(Class<?> aClass) {
return uniqueValueFor(aClass);
}
});
return params.toArray();
Object[] uniqueValues = new Object[parameterTypes.length];
for (int i = 0; i < uniqueValues.length; i++) {
uniqueValues[i] = uniqueValueFor(parameterTypes[i]);
}
return uniqueValues;
}
}