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

New Modules: URI-Builder & Hamcrest Matchers #4

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<module>utils</module>
<module>lang-de</module>

<module>web</module>
<module>slf4j</module>

<module>test</module>
Expand Down Expand Up @@ -115,6 +116,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
Expand Down
41 changes: 41 additions & 0 deletions test/matchers/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2019 Redlink GmbH
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.redlink.utils</groupId>
<artifactId>redlink-utils</artifactId>
<version>2.1.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>

<artifactId>hamcrest-matchers</artifactId>
<name>Redlink Hamcrest Matchers</name>


<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright (c) 2019 Redlink GmbH.
*/
package io.redlink.utils.hamcrest;

import java.net.URI;
import java.util.function.Function;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeDiagnosingMatcher;

public final class UriMatchers {

private UriMatchers() {}

public static TypeSafeDiagnosingMatcher<URI> isURI(String uri) {
return isURI(URI.create(uri));
}

public static TypeSafeDiagnosingMatcher<URI> isURI(URI uri) {
return new TypeSafeDiagnosingMatcher<URI>() {
@Override
protected boolean matchesSafely(URI item, Description mismatchDescription) {
mismatchDescription.appendText("URI ").appendValue(item);
return uri == null ? item == null : uri.toASCIIString().equals(item.toASCIIString());
}

@Override
public void describeTo(Description description) {
description.appendText("URI ").appendValue(uri);
}
};
}

public static TypeSafeDiagnosingMatcher<URI> hasScheme(String scheme) {
return hasScheme(CoreMatchers.is(scheme));
}

public static TypeSafeDiagnosingMatcher<URI> hasScheme(Matcher<String> schemeMatcher) {
return create("scheme", schemeMatcher, URI::getScheme);
}

public static TypeSafeDiagnosingMatcher<URI> hasHost(String host) {
return hasHost(CoreMatchers.is(host));
}

public static TypeSafeDiagnosingMatcher<URI> hasHost(Matcher<String> hostMatcher) {
return create("host", hostMatcher, URI::getHost);
}

public static TypeSafeDiagnosingMatcher<URI> hasPort(int port) {
return hasPort(CoreMatchers.is(port));
}

public static TypeSafeDiagnosingMatcher<URI> hasPort(Matcher<Integer> portMatcher) {
return create("port", portMatcher, URI::getPort);
}

public static TypeSafeDiagnosingMatcher<URI> hasPath(String path) {
return hasPath(CoreMatchers.is(path));
}

public static TypeSafeDiagnosingMatcher<URI> hasPath(Matcher<String> pathMatcher) {
return create("path", pathMatcher, URI::getPath);
}

public static TypeSafeDiagnosingMatcher<URI> hasFragment(String fragment) {
return hasFragment(CoreMatchers.is(fragment));
}

public static TypeSafeDiagnosingMatcher<URI> hasFragment(Matcher<String> fragmentMatcher) {
return create("fragment", fragmentMatcher, URI::getFragment);
}

private static <T> TypeSafeDiagnosingMatcher<URI> create(String uriPart, Matcher<T> partMatcher, Function<URI, T> fkt) {
return new TypeSafeDiagnosingMatcher<URI>() {
@Override
protected boolean matchesSafely(URI item, Description mismatchDescription) {
if (item == null) {
mismatchDescription.appendText("URI ").appendValue(null);
return false;
}

mismatchDescription.appendText("URI with ").appendText(uriPart).appendText(" ");
partMatcher.describeMismatch(fkt.apply(item), mismatchDescription);

return partMatcher.matches(fkt.apply(item));
}

@Override
public void describeTo(Description description) {
description.appendText("URI with ").appendText(uriPart).appendText(" ")
.appendDescriptionOf(partMatcher);
}
};
}

}
21 changes: 3 additions & 18 deletions test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,14 @@
<version>2.1.0-SNAPSHOT</version>
</parent>

<artifactId>test</artifactId>
<groupId>io.redlink.utils.test</groupId>
<artifactId>test-utils</artifactId>
<packaging>pom</packaging>
<name>Redlink Test Utilities</name>

<modules>
<module>testcontainers</module>
<module>matchers</module>
</modules>

<build>
<plugins>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

</project>
2 changes: 1 addition & 1 deletion test/testcontainers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@
</dependency>
</dependencies>

</project>
</project>
55 changes: 55 additions & 0 deletions web/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2019 redlink GmbH
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.redlink.utils</groupId>
<artifactId>redlink-utils</artifactId>
<version>2.1.0-SNAPSHOT</version>
</parent>

<artifactId>web</artifactId>
<packaging>pom</packaging>
<name>Redlink Web Utilities</name>

<modules>
<module>uri-builder</module>
</modules>

<build>
<plugins>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>


</project>
51 changes: 51 additions & 0 deletions web/uri-builder/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2019 redlink GmbH
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.redlink.utils</groupId>
<artifactId>redlink-utils</artifactId>
<version>2.1.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>

<artifactId>uri-builder</artifactId>
<name>URI Builder</name>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.redlink.utils</groupId>
<artifactId>hamcrest-matchers</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Loading