Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.itsallcode.openfasttrace.api;

import java.util.Collections;
import java.util.Objects;
import java.util.Set;

Expand All @@ -27,7 +26,7 @@ private FilterSettings(final Builder builder)
*/
public Set<String> getArtifactTypes()
{
return this.artifactTypes;
return Set.copyOf(this.artifactTypes);
}

/**
Expand All @@ -38,7 +37,7 @@ public Set<String> getArtifactTypes()

public Set<String> getTags()
{
return this.tags;
return Set.copyOf(this.tags);
}

/**
Expand Down Expand Up @@ -122,8 +121,8 @@ public static Builder builder()
*/
public static final class Builder
{
private Set<String> artifactTypes = Collections.emptySet();
private Set<String> tags = Collections.emptySet();
private Set<String> artifactTypes = Set.of();
private Set<String> tags = Set.of();
private boolean withoutTags = true;

private Builder()
Expand Down Expand Up @@ -158,7 +157,7 @@ public Builder tags(final Set<String> tags)
}

/**
* Configure if filter allows items that have no tags.
* Configure if the filter allows items that have no tags.
*
* @param noTags
* {@code true} to match items without any tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;

import org.itsallcode.openfasttrace.api.importer.input.InputFile;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

/**
* Unit test for {@link AbstractImporterFactory}.
Expand All @@ -20,7 +20,7 @@ class TestAbstractImporterFactory
@BeforeEach
void setUp()
{
context = Mockito.mock(ImporterContext.class);
context = mock(ImporterContext.class);
importerFactory = new TestingImporterFactory();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,40 @@
import org.itsallcode.openfasttrace.api.importer.input.InputFile;
import org.itsallcode.openfasttrace.api.importer.input.RealFileInput;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

/**
* Test to reproduce the classloader mismatch problem when discovering
* importers.
* <p>
* This scenario will happen if OFT is used as a library with a custom classloader.
* What we want in that case is a very clear exception message because without
* an importer, neither tracing nor converting have any chance to work.
* This scenario will happen if OFT is used as a library with a custom
* classloader. What we want in that case is a very clear exception message
* because without an importer, neither tracing nor converting does have any
* chance to work.
* </p>
*/
@ExtendWith(MockitoExtension.class)
class ImporterFactoryLoaderClassloaderIT
{
/**
* This test demonstrates that if the Thread Context ClassLoader (TCCL)
* does not have access to the importer factories, {@link ImporterFactoryLoader}
* This test demonstrates that if the Thread Context ClassLoader (TCCL) does
* not have access to the importer factories, {@link ImporterFactoryLoader}
* will fail to find any importers and should throw an exception.
*/
@Test
final void testGetImporterFactoryThrowsExceptionWhenTcclIsLimited()
final void testGetImporterFactoryThrowsExceptionWhenTcclIsLimited(@Mock final ImporterContext context)
{
final ClassLoader originalTccl = Thread.currentThread().getContextClassLoader();
final ClassLoader limitedClassLoader = new NoOpClassLoader();

try
{
Thread.currentThread().setContextClassLoader(limitedClassLoader);
final ImporterContext context = Mockito.mock(ImporterContext.class);
final ImporterFactoryLoader loaderWithLimitedTccl = new ImporterFactoryLoader(context);
final InputFile file = RealFileInput.forPath(Paths.get("test.md"));
final ImporterException exception = assertThrows(ImporterException.class, () ->
loaderWithLimitedTccl.getImporterFactory(file)
);
final ImporterException exception = assertThrows(ImporterException.class,
() -> loaderWithLimitedTccl.getImporterFactory(file));
assertThat(exception.getMessage().contains("No importers discovered"), is(true));
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import org.hamcrest.Matcher;
import org.hamcrest.collection.IsEmptyIterable;
Expand Down Expand Up @@ -54,8 +53,8 @@ public static Matcher<Iterable<? extends SpecificationItemId>> equalIds(
return IsEmptyIterable.emptyIterable();
}
final List<Matcher<? super SpecificationItemId>> matchers = expected.stream()
.map(SpecificationItemIdMatcher::equalTo)
.collect(Collectors.toList());
.<Matcher<? super SpecificationItemId>>map(SpecificationItemIdMatcher::equalTo)
.toList();
return IsIterableContainingInAnyOrder.containsInAnyOrder(matchers);
}
}
Loading