Skip to content

Commit

Permalink
Merge branch 'main' into 2.9.x
Browse files Browse the repository at this point in the history
  • Loading branch information
atextor committed Jul 22, 2024
2 parents 71af28c + ea3413e commit aa5bd64
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,18 @@ public static Class<?> getDataTypeClass( final Type dataType ) {
* Convert a string given as upper or lower camel case into a constant format. For example {@code someVariable} would become
* {@code SOME_VARIABLE}.
*
* @param upperOrLowerCamelString the string to convert
* @param upperOrLowerCamel the string to convert
* @return the string formatted as a constant.
*/
public static String toConstant( final String upperOrLowerCamelString ) {
return TO_CONSTANT.convert( StringUtils.capitalize( upperOrLowerCamelString ) );
public static String toConstant( final String upperOrLowerCamel ) {
if ( isAllUppercaseWithUnderscore( upperOrLowerCamel ) ) {
return upperOrLowerCamel;
}
return TO_CONSTANT.convert( StringUtils.capitalize( upperOrLowerCamel ) );
}

public static boolean isAllUppercaseWithUnderscore( final String upperOrLowerCamel ) {
return upperOrLowerCamel != null && upperOrLowerCamel.matches( "[A-Z0-9_]+" );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@

package org.eclipse.esmf.aspectmodel.java;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.eclipse.esmf.metamodel.Type;
import org.eclipse.esmf.metamodel.Value;
import org.eclipse.esmf.test.shared.arbitraries.PropertyBasedTest;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import net.jqwik.api.ForAll;
import net.jqwik.api.Property;
import net.jqwik.api.Tuple;
Expand All @@ -43,4 +49,25 @@ public boolean generatedEnumKeysAreValidJavaIdentifiers( @ForAll( "anyValidTypeV
final String result = AspectModelJavaUtil.generateEnumKey( tuple.get2() );
return isValidJavaIdentifier( result );
}

@ParameterizedTest
@MethodSource
void generatedEnumKeysAreExpectedEnumNames( final String enumValueName, final String expectedEnumValueName ) {
final String result = AspectModelJavaUtil.toConstant( enumValueName );
assertThat( result ).isEqualTo( expectedEnumValueName );
}

static Stream<Arguments> generatedEnumKeysAreExpectedEnumNames() {
return Stream.of(
Arguments.arguments( "ABC", "ABC" ),
Arguments.arguments( "abc", "ABC" ),
Arguments.arguments( "someEnum", "SOME_ENUM" ),
Arguments.arguments( "SOME_ENUM", "SOME_ENUM" ),
Arguments.arguments( "SomeEnum", "SOME_ENUM" ),
Arguments.arguments( "aB", "A_B" ),
Arguments.arguments( "aBc", "A_BC" ),
Arguments.arguments( "a_b_c", "A_B_C" )
);
}

}

0 comments on commit aa5bd64

Please sign in to comment.