Skip to content

Commit

Permalink
build: Final structure of poms
Browse files Browse the repository at this point in the history
  • Loading branch information
pawellabaj committed Jul 29, 2023
1 parent 3123c9a commit 3d47c5d
Show file tree
Hide file tree
Showing 70 changed files with 527 additions and 228 deletions.
65 changes: 22 additions & 43 deletions extensions/immutable-collections-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
<relativePath>../../pom.xml</relativePath>
</parent>

<url>https://github.com/pawellabaj/auto-record/extensions/immutable-collections-tests</url>
<artifactId>auto-record-immutable-collections-tests</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<guava.version>32.1.1-jre</guava.version>
<maven.install.skip>true</maven.install.skip>
<license-maven-plugin.header>${project.basedir}/../../.build/lic-header.txt</license-maven-plugin.header>
</properties>
Expand All @@ -23,16 +23,12 @@
<dependency>
<groupId>pl.com.labaj</groupId>
<artifactId>auto-record</artifactId>
<version>2.1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>pl.com.labaj</groupId>
<artifactId>auto-record-immutable-collections</artifactId>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<scope>test</scope>
<version>${project.version}</version>
</dependency>

<dependency>
Expand All @@ -52,42 +48,6 @@
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>pl.com.labaj</groupId>
<artifactId>auto-record</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>pl.com.labaj</groupId>
<artifactId>auto-record-immutable-collections</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>com.mycila</groupId>
<artifactId>license-maven-plugin</artifactId>
<configuration>
<licenseSets>
<licenseSet>
<header>${license-maven-plugin.header}</header>
</licenseSet>
</licenseSets>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>verify</id>
Expand All @@ -96,5 +56,24 @@
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/../../target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>
</profile>
<profile>
<id>release</id>

<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<extensions>true</extensions>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package pl.com.labaj.autorecord.extension.arice;

/*-
* Copyright © 2023 Auto Record
*
* 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.
*/

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.util.AbstractCollection;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.NavigableSet;
import java.util.Queue;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Stream;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static pl.com.labaj.autorecord.extension.arice.ImmutabilityTest.TestArgument.data;

class ImmutabilityTest {

@SuppressWarnings("unchecked")
static Stream<Arguments> testData() {
var aValue = "A";
return Stream.of(
data(Collection.class, TestCollection::new, collection -> collection.add(aValue)),
data(Set.class, HashSet::new, set -> set.add(aValue)),
data(SortedSet.class, TreeSet::new, set -> set.add(aValue)),
data(NavigableSet.class, TreeSet::new, set -> set.add(aValue)),
data(List.class, ArrayList::new, list -> list.add(aValue)),
data(Queue.class, ArrayDeque::new, queue -> queue.add(aValue)),
data(Deque.class, ArrayDeque::new, queue -> queue.add(aValue)),
data(Map.class, HashMap::new, map -> map.put(aValue, aValue))
);
}

@SuppressWarnings({"rawtypes", "unchecked"})
@ParameterizedTest(name = "{0}")
@MethodSource("testData")
void shouldWrapCollectionWithImmutable(Class aClass, Supplier mutableValueSupplier, Consumer methodToCall) {
//given
var mutableValue = mutableValueSupplier.get();

//when
var simpleRecord = new SimpleRecord(mutableValue);
var immutableValue = simpleRecord.value();

System.out.println(mutableValue.getClass() + " -> " + immutableValue.getClass());

//then
assertAll(
() -> assertThat(immutableValue).isInstanceOf(aClass),
() -> assertDoesNotThrow(() -> methodToCall.accept(mutableValue)),
() -> assertThrows(UnsupportedOperationException.class, () -> methodToCall.accept(immutableValue))
);
}

record TestArgument<E>(Class<E> aClass, Supplier<? extends E> mutableValueSupplier, Consumer<E> methodToCall) implements Arguments {

static <E> TestArgument<E> data(Class<E> aClass, Supplier<? extends E> mutableValueSupplier, Consumer<E> methodToCall) {
return new TestArgument<>(aClass, mutableValueSupplier, methodToCall);
}

@Override
public Object[] get() {
return new Object[] {aClass, mutableValueSupplier, methodToCall};
}
}

private static class TestCollection<E> extends AbstractCollection<E> implements Collection<E> {
@Override
public Iterator<E> iterator() {
return new Iterator<E>() {
@Override
public boolean hasNext() {
return false;
}

@Override
public E next() {
return null;
}
};
}

@Override
public int size() {
return 0;
}

@Override
public boolean add(E e) {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package pl.com.labaj.autorecord.extension.arice;

/*-
* Copyright © 2023 Auto Record
*
* 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.
*/

import pl.com.labaj.autorecord.AutoRecord;

@AutoRecord
@AutoRecord.Extension(extensionClass = "pl.com.labaj.autorecord.extension.arice.ImmutableCollectionsExtension")
interface Simple {
Object value();
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
import pl.com.labaj.autorecord.GeneratedWithAutoRecord;
import pl.com.labaj.autorecord.extension.arice.ARICE;
import pl.com.labaj.autorecord.extension.arice.AutoRecordImmutableCollectionsUtilities;
import pl.com.labaj.autorecord.extension.arice.Methods;
import pl.com.labaj.autorecord.testcase.user.UserCollections;

@Generated("pl.com.labaj.autorecord.AutoRecord")
@GeneratedWithAutoRecord
@AutoRecordImmutableCollectionsUtilities(className = "pl.com.labaj.autorecord.extension.arice.Methods")
@AutoRecordImmutableCollectionsUtilities(className = "pl.com.labaj.autorecord.extension.arice.ARICE")
record ItemWithListsNoUserDefinedCollectionsRecord<E>(List<E> list,
LinkedList<E> linkedList,
ArrayList<E> arrayList,
Expand All @@ -55,7 +55,7 @@ record ItemWithListsNoUserDefinedCollectionsRecord<E>(List<E> list,
requireNonNull(immutableList, "immutableList must not be null");

// pl.com.labaj.autorecord.extension.arice.ImmutableCollectionsExtension
list = Methods.immutable(list);
nullableList = isNull(nullableList) ? null : Methods.immutable(nullableList);
list = ARICE.immutable(list);
nullableList = isNull(nullableList) ? null : ARICE.immutable(nullableList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
import pl.com.labaj.autorecord.GeneratedWithAutoRecord;
import pl.com.labaj.autorecord.extension.arice.ARICE_JKSTKLE;
import pl.com.labaj.autorecord.extension.arice.AutoRecordImmutableCollectionsUtilities;
import pl.com.labaj.autorecord.extension.arice.Methods_JKSTKMJ;
import pl.com.labaj.autorecord.testcase.user.UserCollections;

@Generated("pl.com.labaj.autorecord.AutoRecord")
@GeneratedWithAutoRecord
@AutoRecordImmutableCollectionsUtilities(
className = "pl.com.labaj.autorecord.extension.arice.Methods_JKSTKMJ",
className = "pl.com.labaj.autorecord.extension.arice.ARICE_JKSTKLE",
immutableTypes = "pl.com.labaj.autorecord.testcase.user.UserCollections.UserList"
)
record ItemWithListsRecord<E>(List<E> list,
Expand All @@ -58,7 +58,7 @@ record ItemWithListsRecord<E>(List<E> list,
requireNonNull(immutableList, "immutableList must not be null");

// pl.com.labaj.autorecord.extension.arice.ImmutableCollectionsExtension
list = Methods_JKSTKMJ.immutable(list);
nullableList = isNull(nullableList) ? null : Methods_JKSTKMJ.immutable(nullableList);
list = ARICE_JKSTKLE.immutable(list);
nullableList = isNull(nullableList) ? null : ARICE_JKSTKLE.immutable(nullableList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
import pl.com.labaj.autorecord.GeneratedWithAutoRecord;
import pl.com.labaj.autorecord.extension.arice.ARICE_KMBEBUW;
import pl.com.labaj.autorecord.extension.arice.AutoRecordImmutableCollectionsUtilities;
import pl.com.labaj.autorecord.extension.arice.Methods_LIBZVBZLV;
import pl.com.labaj.autorecord.testcase.user.UserCollections;

@Generated("pl.com.labaj.autorecord.AutoRecord")
@GeneratedWithAutoRecord
@AutoRecordImmutableCollectionsUtilities(
className = "pl.com.labaj.autorecord.extension.arice.Methods_LIBZVBZLV",
className = "pl.com.labaj.autorecord.extension.arice.ARICE_KMBEBUW",
immutableTypes = {
"pl.com.labaj.autorecord.testcase.user.UserCollections.UserMap",
"pl.com.labaj.autorecord.testcase.user.UserCollections.UserNavigableMap",
Expand Down Expand Up @@ -82,11 +82,11 @@ record ItemWithMapsRecord<K, V>(Map<K, V> set,
requireNonNull(immutableMap, "immutableMap must not be null");

// pl.com.labaj.autorecord.extension.arice.ImmutableCollectionsExtension
set = Methods_LIBZVBZLV.immutable(set);
sortedMap = Methods_LIBZVBZLV.immutable(sortedMap);
navigableMap = Methods_LIBZVBZLV.immutable(navigableMap);
nullableSet = isNull(nullableSet) ? null : Methods_LIBZVBZLV.immutable(nullableSet);
nullableSortedMap = isNull(nullableSortedMap) ? null : Methods_LIBZVBZLV.immutable(nullableSortedMap);
nullableNavigableMap = isNull(nullableNavigableMap) ? null : Methods_LIBZVBZLV.immutable(nullableNavigableMap);
set = ARICE_KMBEBUW.immutable(set);
sortedMap = ARICE_KMBEBUW.immutable(sortedMap);
navigableMap = ARICE_KMBEBUW.immutable(navigableMap);
nullableSet = isNull(nullableSet) ? null : ARICE_KMBEBUW.immutable(nullableSet);
nullableSortedMap = isNull(nullableSortedMap) ? null : ARICE_KMBEBUW.immutable(nullableSortedMap);
nullableNavigableMap = isNull(nullableNavigableMap) ? null : ARICE_KMBEBUW.immutable(nullableNavigableMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
import javax.annotation.Nullable;
import javax.annotation.processing.Generated;
import pl.com.labaj.autorecord.GeneratedWithAutoRecord;
import pl.com.labaj.autorecord.extension.arice.ARICE;
import pl.com.labaj.autorecord.extension.arice.AutoRecordImmutableCollectionsUtilities;
import pl.com.labaj.autorecord.extension.arice.Methods;

@Generated("pl.com.labaj.autorecord.AutoRecord")
@GeneratedWithAutoRecord
@AutoRecordImmutableCollectionsUtilities(className = "pl.com.labaj.autorecord.extension.arice.Methods")
@AutoRecordImmutableCollectionsUtilities(className = "pl.com.labaj.autorecord.extension.arice.ARICE")
record ItemWithObjectRecord(Object object, @Nullable Object nullableObject) implements ItemWithObject {
ItemWithObjectRecord {
// pl.com.labaj.autorecord.processor.AutoRecordProcessor
requireNonNull(object, "object must not be null");

// pl.com.labaj.autorecord.extension.arice.ImmutableCollectionsExtension
object = Methods.immutable(object);
nullableObject = isNull(nullableObject) ? null : Methods.immutable(nullableObject);
object = ARICE.immutable(object);
nullableObject = isNull(nullableObject) ? null : ARICE.immutable(nullableObject);
}
}
Loading

0 comments on commit 3d47c5d

Please sign in to comment.