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

Upgrade to java 21 #63

Merged
merged 5 commits into from
Nov 15, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/maven_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
java-version: 21
cache: 'maven'
cache-dependency-path: '**/pom.xml'
server-id: 'github'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/maven_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
java-version: 21
cache: 'maven'
cache-dependency-path: '**/pom.xml'
server-id: 'central'
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
java-version: 21
cache: 'maven'
cache-dependency-path: '**/pom.xml'
server-id: 'github'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void shouldDeserializeWithOrRootList() throws Exception {
},
"filterBy": {
"OR": [
{ "GT": { "id": [ "666" ] } }
{ "GT": { "id": [ 666 ] } }
]
},
"pageSize": 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,55 @@ public boolean ignoreCase() {
return ignoreCase;
}

public Comparable<?> verify( Comparable<?> v ) {
if ( type().isAssignableFrom( v.getClass() ) ) {
return type().cast( v );
} else if ( v instanceof Integer && type().isAssignableFrom( Long.class ) ) {
return Long.valueOf( (Integer) v );
} else if ( v instanceof Long && type().isAssignableFrom( Integer.class ) && (Long) v <= Integer.MAX_VALUE ) {
return Integer.valueOf( v.toString() );
public Comparable<?> verify( final Comparable<?> value ) {
if ( type().isAssignableFrom( value.getClass() ) ) {
return type().cast( value );
} else if ( value instanceof Integer && typeIsInteger() ) {
return value;
} else if ( value instanceof Long && typeIsLong() ) {
return value;
} else if ( value instanceof Short && typeIsShort() ) {
return value;
} else if ( value instanceof Character && (type() == Character.class || type() == char.class) ) {
return value;
} else if ( value instanceof Boolean && typeIsBoolean() ) {
return value;
} else if ( value instanceof Byte && (type() == Byte.class || type() == byte.class) ) {
return value;
} else if ( value instanceof Integer && typeIsLong() ) {
return Long.valueOf( (Integer) value );
} else if ( value instanceof Long && typeIsInteger() && ((Long) value) <= Integer.MAX_VALUE ) {
return Integer.valueOf( value.toString() );
} else if ( value instanceof String && typeIsInteger() ) {
return Integer.valueOf( value.toString() );
} else if ( value instanceof String && typeIsLong() ) {
return Long.valueOf( value.toString() );
} else if ( value instanceof String && typeIsShort() ) {
return Short.valueOf( value.toString() );
} else if ( value instanceof String && typeIsBoolean() ) {
return Boolean.valueOf( value.toString() );
} else {
throw new IllegalArgumentException(
"Value %s (%s) is not of type %s".formatted( v, v.getClass().getName(), type() ) );
"Value %s (%s) is not of type %s".formatted( value, value.getClass().getName(), type() ) );
}
}

private boolean typeIsBoolean() {
return type() == Boolean.class || type() == boolean.class;
}

private boolean typeIsShort() {
return type() == Short.class || type() == short.class;
}

private boolean typeIsInteger() {
return type() == Integer.class || type() == int.class;
}

private boolean typeIsLong() {
return type() == Long.class || type() == long.class;
}

public List<? extends Comparable<?>> verify( List<? extends Comparable<?>> values ) {
return values.stream().map( this::verify ).toList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.vigier.cursorpaging.jpa;

import io.vigier.cursorpaging.jpa.Filters.FilterCreator;
import io.vigier.cursorpaging.jpa.itest.model.DataRecord;
import io.vigier.cursorpaging.jpa.itest.model.DataRecord_;
import io.vigier.cursorpaging.jpa.itest.model.Tag_;
import jakarta.persistence.metamodel.SingularAttribute;
import java.util.Set;
import java.util.function.Function;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
Expand Down Expand Up @@ -65,4 +68,34 @@ private static <E extends Comparable<? super E>> void verifyNameAndValue( final
assertThat( f.values( type ) ).containsExactly( values );
} );
}

@Test
void shouldBeEqual() {
shouldBeEqual( f1 -> f1.like( "John" ), f2 -> f2.like( "John" ) );
shouldBeEqual( f1 -> f1.equalTo( "John" ), f2 -> f2.equalTo( "John" ) );
shouldBeEqual( f1 -> f1.greaterThan( "1L" ), f2 -> f2.greaterThan( "1L" ) );
shouldBeEqual( f1 -> f1.lessThan( "1L" ), f2 -> f2.lessThan( "1L" ) );
}

private void shouldBeEqual( Function<FilterCreator, Filter> f1, Function<FilterCreator, Filter> f2 ) {
var name1 = Attribute.of( "name", String.class );
var name2 = Attribute.of( "name", String.class );

Assertions.assertThat( f1.apply( Filters.attribute( name1 ) ) )
.isEqualTo( f2.apply( Filters.attribute( name2 ) ) );
}

@Test
void filterListsShouldBeEqual() {
var nameAndAge1 = Filters.and( Filters.attribute( Attribute.of( "name", String.class ) ).equalTo( "John" ),
Filters.attribute( Attribute.of( "age", Long.class ) ).equalTo( 18 ) );
var nameAndAge2 = Filters.and( Filters.attribute( Attribute.of( "name", String.class ) ).equalTo( "John" ),
Filters.attribute( Attribute.of( "age", Long.class ) ).equalTo( 18 ) );

Assertions.assertThat( nameAndAge1 ).isEqualTo( nameAndAge2 );
Assertions.assertThat( Filters.and( nameAndAge1 ) ).isEqualTo( Filters.and( nameAndAge2 ) );
Assertions.assertThat( Filters.or( nameAndAge1 ) ).isEqualTo( Filters.or( nameAndAge2 ) );

Assertions.assertThat( Filters.or( nameAndAge1 ) ).isNotEqualTo( Filters.and( nameAndAge2 ) );
}
}

This file was deleted.