Skip to content

Commit

Permalink
Clean up repository and add minor utility improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
stijn-dejongh committed Nov 21, 2024
1 parent 30e2670 commit fa5f044
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 64 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/manualRelease.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Release and Publish
on:
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check-out
uses: actions/checkout@v4
- name: Set up Java for publishing to Maven Central Packages
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
server-id: central
server-username: SONATYPE_USERNAME
server-password: SONATYPE_TOKEN
- name: Release with Maven
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
mvn -B -ntp -Dstyle.color=always release:prepare
VERSION=`cat release.properties | grep scm.tag= | cut -d'=' -f2`
mvn -B -ntp -Dstyle.color=always release:perform
echo "Released ${VERSION} 🚀" >> $GITHUB_STEP_SUMMARY
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
SONATYPE_USERNAME: ${{ secrets.OSSRH_USERNAME }}
SONATYPE_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 7 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
name: Release and Publish
name: Publish package to GitHub Packages
on:
workflow_dispatch:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check-out
uses: actions/checkout@v4
- name: Set up Java for publishing to Maven Central Packages
- uses: actions/checkout@v4
- name: Set up Java for publishing to GitHub Packages
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
cache: maven
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
server-id: central
server-username: SONATYPE_USERNAME
server-password: SONATYPE_TOKEN
- name: Release with Maven
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
mvn -B -ntp -Dstyle.color=always release:prepare
VERSION=`cat release.properties | grep scm.tag= | cut -d'=' -f2`
mvn -B -ntp -Dstyle.color=always release:perform
echo "Released ${VERSION} 🚀" >> $GITHUB_STEP_SUMMARY
- name: Publish to GitHub Packages
run: mvn --batch-mode deploy
env:
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
SONATYPE_USERNAME: ${{ secrets.OSSRH_USERNAME }}
SONATYPE_TOKEN: ${{ secrets.OSSRH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions commons-kernel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<artifactId>commons-kernel</artifactId>

<url>https://github.com/sddevelopment-be/coding-utils</url>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
Expand Down
7 changes: 7 additions & 0 deletions commons-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

<artifactId>commons-testing</artifactId>

<description>
This module contains testing utilities included in the sddevelopment.be commons projects.
It is intended to simplify the testing of other modules in java projects.
</description>

<url>https://github.com/sddevelopment-be/coding-utils</url>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*-
* #%L
* commons-testing
* %%
* Copyright (C) 2020 - 2024 SD Development
* %%
* Licensed under the EUPL, Version 1.1 or – as soon they will be
* approved by the European Commission - subsequent versions of the
* EUPL (the "Licence");
*
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl5
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
* #L%
*/

package be.sddevelopment.commons.testing;


import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayNameGeneration;

@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class)
public interface BaseTest extends WithAssertions {

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
* <p>Description of file/class</p>
*
* @author <a href="https://github.com/stijn-dejongh" target="_blank">Stijn Dejongh</a>
* @version $Id: $Id
* @created 18.10.20, Sunday
*/
public final class TextualAssertions {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*-
* #%L
* commons-testing
* %%
* Copyright (C) 2020 - 2024 SD Development
* %%
* Licensed under the EUPL, Version 1.1 or – as soon they will be
* approved by the European Commission - subsequent versions of the
* EUPL (the "Licence");
*
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://ec.europa.eu/idabc/eupl5
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
* #L%
*/

package be.sddevelopment.commons.testing.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.Disabled;

@Disabled("Disabled: Work In Progress")
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface WIP {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
*/

/**
* <p>Description of file/class</p>
* <p>
* This module contains testing utilities included in the sddevelopment.be commons projects.
* It is intended to simplify the testing of other modules in java projects.
* </p>
*
* @author <a href="https://github.com/stijn-dejongh" target="_blank">Stijn Dejongh</a>
* @created 22.10.20, Thursday
**/
package be.sddevelopment.commons.testing;
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* Licensed under the EUPL, Version 1.1 or – as soon they will be
* approved by the European Commission - subsequent versions of the
* EUPL (the "Licence");
*
*
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
*
* http://ec.europa.eu/idabc/eupl5
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -26,18 +26,14 @@
import static be.sddevelopment.commons.testing.ReflectionAssertionUtils.assertPrivateMember;
import static be.sddevelopment.commons.testing.ReflectionAssertionUtils.assertPrivateMemberReflectionProtection;

import be.sddevelopment.commons.testing.naming.ReplaceUnderscoredCamelCasing;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.assertj.core.api.WithAssertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class)
class ReflectionAssertionUtilsTest implements WithAssertions {
class ReflectionAssertionUtilsTest implements BaseTest {

@Test
void constructorIsPrivate() throws NoSuchMethodException {
Expand All @@ -46,16 +42,21 @@ void constructorIsPrivate() throws NoSuchMethodException {

@Test
void constructorIsReflectionSafe() throws NoSuchMethodException {
assertPrivateMemberReflectionProtection(ReflectionAssertionUtils.class.getDeclaredConstructor());
assertPrivateMemberReflectionProtection(
ReflectionAssertionUtils.class.getDeclaredConstructor());
}

@Nested
@DisplayName("Method: assertPrivateMember")
class AssertPrivateMember {

@Test
void passesWhenConstructorIsPrivate() throws NoSuchMethodException {
var constructorToTest = ClassWithPrivateConstructor.class.getDeclaredConstructor();
assertThat(constructorToTest).isNotNull().extracting(Constructor::getModifiers).matches(Modifier::isPrivate);
assertThat(constructorToTest)
.isNotNull()
.extracting(Constructor::getModifiers)
.matches(Modifier::isPrivate);

ThrowingCallable assertion = () -> assertPrivateMember(constructorToTest);

Expand All @@ -65,43 +66,61 @@ void passesWhenConstructorIsPrivate() throws NoSuchMethodException {
@Test
void failsWhenConstructorIsPublic() throws NoSuchMethodException {
var constructorToTest = ClassWithPublicConstructor.class.getDeclaredConstructor();
assertThat(constructorToTest).isNotNull().extracting(Constructor::getModifiers).matches(Modifier::isPublic);
assertThat(constructorToTest)
.isNotNull()
.extracting(Constructor::getModifiers)
.matches(Modifier::isPublic);

ThrowingCallable assertion = () -> assertPrivateMember(constructorToTest);

assertThatCode(assertion).isInstanceOf(AssertionError.class).hasMessageContaining("is expected to be protected from illegal access");
assertThatCode(assertion)
.isInstanceOf(AssertionError.class)
.hasMessageContaining("is expected to be protected from illegal access");
}
}

@Nested
@DisplayName("Method: assertPrivateMemberReflectionProtection")
class AssertPrivateMemberReflectionProtection {

@Test
void failsWhenConstructorIsPublic() throws NoSuchMethodException {
var constructorToTest = ClassWithPublicConstructor.class.getDeclaredConstructor();
assertThat(constructorToTest).isNotNull().extracting(Constructor::getModifiers).matches(Modifier::isPublic);
assertThat(constructorToTest)
.isNotNull()
.extracting(Constructor::getModifiers)
.matches(Modifier::isPublic);

ThrowingCallable assertion = () -> assertPrivateMemberReflectionProtection(constructorToTest);

assertThatCode(assertion).isInstanceOf(AssertionError.class)
.hasMessageContaining("is expected to be protected from illegal access");
assertThatCode(assertion)
.isInstanceOf(AssertionError.class)
.hasMessageContaining("is expected to be protected from illegal access");
}

@Test
void failsWhenConstructorIsPrivateButNotReflectionSafe() throws NoSuchMethodException {
var constructorToTest = ClassWithPrivateConstructor.class.getDeclaredConstructor();
assertThat(constructorToTest).isNotNull().extracting(Constructor::getModifiers).matches(Modifier::isPrivate);
assertThat(constructorToTest)
.isNotNull()
.extracting(Constructor::getModifiers)
.matches(Modifier::isPrivate);

ThrowingCallable assertion = () -> assertPrivateMemberReflectionProtection(constructorToTest);

assertThatCode(assertion).isNotNull().isInstanceOf(AssertionError.class)
.hasMessageContaining("is expected to be protected from illegal access");
assertThatCode(assertion)
.isNotNull()
.isInstanceOf(AssertionError.class)
.hasMessageContaining("is expected to be protected from illegal access");
}

@Test
void passesWhenConstructorIsPrivateAndReflectionSafe() throws NoSuchMethodException {
var constructorToTest = ClassWithReflectionSafeConstructor.class.getDeclaredConstructor();
assertThat(constructorToTest).isNotNull().extracting(Constructor::getModifiers).matches(Modifier::isPrivate);
assertThat(constructorToTest)
.isNotNull()
.extracting(Constructor::getModifiers)
.matches(Modifier::isPrivate);

ThrowingCallable assertion = () -> assertPrivateMemberReflectionProtection(constructorToTest);

Expand All @@ -110,17 +129,21 @@ void passesWhenConstructorIsPrivateAndReflectionSafe() throws NoSuchMethodExcept
}

static final class ClassWithReflectionSafeConstructor {

private ClassWithReflectionSafeConstructor() {
throw new UnsupportedOperationException("Utility classes should not have a public or default constructor");
throw new UnsupportedOperationException(
"Utility classes should not have a public or default constructor");
}
}

static final class ClassWithPrivateConstructor {

private ClassWithPrivateConstructor() {
}
}

static final class ClassWithPublicConstructor {

public ClassWithPublicConstructor() {
// Intentionally left empty to test the assertion
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
* @version $Id: $Id
*/
@DisplayName("Test for AssertionUtils")
@DisplayNameGeneration(ReplaceUnderscoredCamelCasing.class)
class TextualAssertionsTest {
class TextualAssertionsTest implements BaseTest{

@Nested
@DisplayName("Test with empty input")
Expand Down
6 changes: 6 additions & 0 deletions commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

<artifactId>commons</artifactId>

<description>
This module contains utilities, shared exceptions, and constants, included in the sddevelopment.be commons projects.
</description>

<url>https://github.com/sddevelopment-be/coding-utils</url>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
Expand Down
Loading

0 comments on commit fa5f044

Please sign in to comment.