Skip to content

Commit

Permalink
Merge pull request #41 from ocadotechnology/test-arranger-40
Browse files Browse the repository at this point in the history
test-arranger-40:  someFrom throws exception
  • Loading branch information
mjureczko authored Sep 14, 2022
2 parents 55be7f1 + aa7316d commit 19c9f5e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.ocadotechnology.gembus</groupId>
<artifactId>test-arranger</artifactId>
<version>1.4.3</version>
<version>1.4.4</version>
<packaging>jar</packaging>
<name>test-arranger</name>
<description>A tool for arranging test data with pseudo-random values.</description>
Expand Down Expand Up @@ -113,7 +113,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.21.0</version>
<version>3.23.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -129,7 +129,7 @@
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.8.1</version>
<version>5.9.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -184,7 +184,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.10.1</version>
<executions>
<!-- Replacing default-compile and default-testCompile as it is treated specially by maven -->
<execution>
Expand Down Expand Up @@ -273,7 +273,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<version>1.6.13</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand All @@ -299,7 +299,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<version>3.4.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/ocadotechnology/gembus/test/Arranger.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ public static <T> T some(final Class<T> type, final Map<String, Supplier<?>> ove

/**
* @see org.jeasy.random.EasyRandom#nextObject
* @deprecated
* This methods creates a lot of complexity resulting in lesser performance and increased memory consumption.
* @deprecated This methods creates a lot of complexity resulting in lesser performance and increased memory consumption.
* Use {@link Arranger#some(Class, String...)} instead.
*/
public static <T> T someSimplified(final Class<T> type, final String... excludedFields) {
Expand Down Expand Up @@ -245,7 +244,8 @@ public static <T> T someFrom(Collection<T> source) {
if (source instanceof List) {
return ((List<T>) source).get(new Random().nextInt(source.size()));
} else {
return source.stream().skip(new Random().nextInt(source.size() - 1)).findFirst().get();
int index = Math.max(source.size() - 1, new Random().nextInt(source.size()));
return source.stream().skip(index).findFirst().get();
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/java/com/ocadotechnology/gembus/test/ArrangerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ void someFromList() {
}
}

@Test
void someFromSetOfSizeOne(){
//given
final Set<Integer> listOfSizeOne = Collections.singleton(Arranger.someInteger());

//when
Integer selected = Arranger.someFrom(listOfSizeOne);

//then
assertThat(selected).isEqualTo(listOfSizeOne.iterator().next());
}

@Test
void someFromCollection() {
//given
Expand Down

0 comments on commit 19c9f5e

Please sign in to comment.