Updated Slf4j, and ModelCollectionTests.

This commit is contained in:
JesseBrault0709 2023-06-12 09:36:01 +02:00
parent 956642339c
commit 2208c9f4c0
4 changed files with 58 additions and 15 deletions

View File

@ -4,6 +4,10 @@ import com.jessebrault.ssg.model.Model
import groovy.transform.EqualsAndHashCode
import groovy.transform.NullCheck
import org.jetbrains.annotations.Nullable
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.slf4j.Marker
import org.slf4j.MarkerFactory
import java.util.function.Predicate
@ -11,6 +15,10 @@ import java.util.function.Predicate
@EqualsAndHashCode(includeFields = true)
final class ModelCollection<T> {
private static final Logger logger = LoggerFactory.getLogger(ModelCollection)
private static final Marker enter = MarkerFactory.getMarker('ENTER')
private static final Marker exit = MarkerFactory.getMarker('EXIT')
@Delegate
private final Collection<Model<T>> models = []
@ -36,11 +44,20 @@ final class ModelCollection<T> {
Optional.ofNullable(this.getByNameAndType(name, type))
}
def <E extends T> ModelCollection<E> findAllByType(Class<E> type) {
def <E> ModelCollection<E> findAllByType(Class<E> type) {
logger.trace(enter, 'type: {}', type)
def es = this.models.findResults {
type.isAssignableFrom(it.get().class) ? it as Model<E> : null
def itType = it.get().class
def itResult = type.isAssignableFrom(itType)
logger.debug(
'it: {}, itType: {}, itType.classLoader: {}, itResult: {}',
it, itType, itType.classLoader, itResult
)
itResult ? it as Model<E> : null
}
new ModelCollection<>(es)
def result = new ModelCollection<>(es)
logger.trace(exit, 'result: {}', result)
result
}
def <E extends T> Optional<Model<E>> findOne(Class<E> type, Predicate<E> filter) {

View File

@ -0,0 +1,26 @@
package com.jessebrault.ssg.dsl
import com.jessebrault.ssg.model.Models
import org.junit.jupiter.api.Test
import static org.junit.jupiter.api.Assertions.assertEquals
final class ModelCollectionTests {
interface Message {}
static final class TextMessage implements Message {}
static final class MailMessage implements Message {}
@Test
void findAllByType() {
def textModel = Models.of('text', new TextMessage())
def mailModel = Models.of('mail', new MailMessage())
def models = new ModelCollection([textModel, mailModel])
assertEquals(2, models.findAllByType(Message).size())
assertEquals(1, models.findAllByType(TextMessage).size())
assertEquals(1, models.findAllByType(MailMessage).size())
}
}

View File

@ -23,9 +23,9 @@ dependencies {
* Logging
*/
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
api 'org.slf4j:slf4j-api:1.7.36'
api 'org.slf4j:slf4j-api:2.0.7'
testFixturesApi 'org.slf4j:slf4j-api:1.7.36'
testFixturesApi 'org.slf4j:slf4j-api:2.0.7'
/**
* TESTING
@ -48,17 +48,17 @@ dependencies {
/**
* Test Logging
*/
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j2-impl
testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j2-impl:2.20.0'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
testRuntimeOnly 'org.apache.logging.log4j:log4j-core:2.19.0'
testRuntimeOnly 'org.apache.logging.log4j:log4j-core:2.20.0'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
testFixturesRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j2-impl
testFixturesRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j2-impl:2.20.0'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
testFixturesRuntimeOnly 'org.apache.logging.log4j:log4j-core:2.19.0'
testFixturesRuntimeOnly 'org.apache.logging.log4j:log4j-core:2.20.0'
}
test {

View File

@ -17,13 +17,13 @@ dependencies {
* Logging
*/
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api
implementation 'org.apache.logging.log4j:log4j-api:2.19.0'
implementation 'org.apache.logging.log4j:log4j-api:2.20.0'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j2-impl
runtimeOnly 'org.apache.logging.log4j:log4j-slf4j2-impl:2.20.0'
// https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
implementation 'org.apache.logging.log4j:log4j-core:2.20.0'
}
application {