Skip to content

Commit

Permalink
performance improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
mjureczko committed Oct 30, 2023
1 parent c5223fd commit 8890412
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/ocadotechnology/gembus/test/Arranger.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public static <T> T some(final Class<T> type, final String... excludedFields) {
* @return a random instance of the given type
*/
public static <T> T some(final Class<T> type, final Map<String, Supplier<?>> overrides) {
T result = random.nextObject(type);
String[] toIgnore = overrides.keySet().toArray(new String[overrides.size()]);
T result = random.nextObject(type, toIgnore);
OverridesHelper.applyOverrides(result, overrides);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright © 2020 Ocado ([email protected])
*
* 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.
*/
package com.ocadotechnology.gembus.test;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;

import static com.ocadotechnology.gembus.test.Arranger.some;
import static org.assertj.core.api.Assertions.assertThat;

public class ArrangerTestEnumSet {

@Test
@DisplayName("SHOULD not try to initialize file WHEN an override is delivered")
void skipEnumSet() {
//when
Map<String, Supplier<?>> overrides = new HashMap<String, Supplier<?>>(){{
put("enumeration", () -> null);
}};
ClassWithEnumSetField some = some(ClassWithEnumSetField.class, overrides);

//then
assertThat(some.txt).isNotBlank();
assertThat(some.enumeration).isNull();
}
}

class ClassWithEnumSetField {
String txt;
EnumSet<SomeEnum> enumeration;
}

enum SomeEnum {
ONE,
TWO,
THREE
}

0 comments on commit 8890412

Please sign in to comment.