Skip to content

Commit

Permalink
chore: replace Arrays.asList with List.of
Browse files Browse the repository at this point in the history
  • Loading branch information
jbee committed Nov 28, 2023
1 parent 1f59cf8 commit 5edc089
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 154 deletions.
5 changes: 2 additions & 3 deletions src/test/java/org/hisp/dhis/rules/ConstantsValueTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.junit.runners.JUnit4;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -110,7 +109,7 @@ public void assignValue()
org.hisp.dhis.rules.models.Rule rule2 = org.hisp.dhis.rules.models.Rule
.create( null, 1, "#{test_attribute} > 3", List.of(action), "test_program_rule2", "" );

RuleEngine.Builder ruleEngineBuilder = getRuleEngine( Arrays.asList( rule, rule2 ),
RuleEngine.Builder ruleEngineBuilder = getRuleEngine( List.of( rule, rule2 ),
new HashMap<>() );

RuleEnrollment enrollment = RuleEnrollment.builder()
Expand Down Expand Up @@ -145,7 +144,7 @@ public void assignValueThroughVariable()
org.hisp.dhis.rules.models.Rule rule2 = org.hisp.dhis.rules.models.Rule
.create( null, 1, "#{test_attribute} > 3", List.of(action), "test_program_rule2", "" );

RuleEngine.Builder ruleEngineBuilder = getRuleEngine( Arrays.asList( rule, rule2 ),
RuleEngine.Builder ruleEngineBuilder = getRuleEngine( List.of( rule, rule2 ),
new HashMap<>() );

RuleEnrollment enrollment = RuleEnrollment.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.hisp.dhis.rules.models.RuleEnrollment;
import org.hisp.dhis.rules.models.RuleEvent;
import org.hisp.dhis.rules.models.TriggerEnvironment;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/hisp/dhis/rules/RuleEngineContextTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.junit.runners.JUnit4;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -48,7 +47,7 @@ public void builderShouldThrowOnNullRulesList()
@Test
public void builderShouldContainImmutableCopyOfRules()
{
List<String> members = Arrays.asList( "one", "two" );
List<String> members = List.of( "one", "two" );
Map<String, List<String>> supplementaryData = new HashMap<>();
supplementaryData.put( "text-key", members );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import org.hisp.dhis.rules.models.RuleAction;
import org.hisp.dhis.rules.models.RuleActionAssign;
import org.hisp.dhis.rules.models.RuleActionCreateEvent;
import org.hisp.dhis.rules.models.RuleActionMessage;
import org.hisp.dhis.rules.models.RuleActionText;
import org.hisp.dhis.rules.models.RuleActionHideField;
import org.hisp.dhis.rules.models.RuleActionHideOption;
import org.hisp.dhis.rules.models.RuleActionHideOptionGroup;
import org.hisp.dhis.rules.models.RuleActionHideProgramStage;
import org.hisp.dhis.rules.models.RuleActionHideSection;
import org.hisp.dhis.rules.models.RuleActionMessage;
import org.hisp.dhis.rules.models.RuleActionScheduleMessage;
import org.hisp.dhis.rules.models.RuleActionSetMandatoryField;
import org.hisp.dhis.rules.models.RuleActionText;
import org.hisp.dhis.rules.models.RuleDataValue;
import org.hisp.dhis.rules.models.RuleEffect;
import org.hisp.dhis.rules.models.RuleEffects;
Expand Down
119 changes: 59 additions & 60 deletions src/test/java/org/hisp/dhis/rules/RuleEngineFunctionTest.java

Large diffs are not rendered by default.

54 changes: 27 additions & 27 deletions src/test/java/org/hisp/dhis/rules/RuleEngineVariableNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void evaluateD2Round()
ruleVariables );

RuleEvent ruleEvent = RuleEvent.create( "test_event", "test_program_stage",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element1", "2.6" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element2", "2.6" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element3", "2.6" ),
Expand Down Expand Up @@ -198,7 +198,7 @@ RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create(new Date(), "test_program_stage", "test_data_element_one", "condition")), "", null);

ruleEngineBuilder.events( Arrays.asList( ruleEvent2, ruleEvent3 ) );
ruleEngineBuilder.events( List.of( ruleEvent2, ruleEvent3 ) );

List<RuleEffect> ruleEffects = ruleEngineBuilder.build().evaluate( ruleEvent ).call();

Expand Down Expand Up @@ -230,7 +230,7 @@ RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create(new Date(), "test_program_stage", "test_data_element_one", "condition")), "", null);

ruleEngineBuilder.events( Arrays.asList( ruleEvent2, ruleEvent3 ) );
ruleEngineBuilder.events( List.of( ruleEvent2, ruleEvent3 ) );

List<RuleEffect> ruleEffects = ruleEngineBuilder.build().evaluate( ruleEvent ).call();

Expand Down Expand Up @@ -269,7 +269,7 @@ RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create(new Date(), "test_program_stage", "test_data_element_two", "condition")), "", null);

ruleEngineBuilder.events( Arrays.asList( ruleEvent2, ruleEvent3, ruleEvent4 ) );
ruleEngineBuilder.events( List.of( ruleEvent2, ruleEvent3, ruleEvent4 ) );

List<RuleEffect> ruleEffects = ruleEngineBuilder.build().evaluate( ruleEvent ).call();

Expand Down Expand Up @@ -308,7 +308,7 @@ RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create(new Date(), "test_program_stage", "test_data_element_two", "condition")), "", null);

ruleEngineBuilder.events( Arrays.asList( ruleEvent2, ruleEvent3, ruleEvent4 ) );
ruleEngineBuilder.events( List.of( ruleEvent2, ruleEvent3, ruleEvent4 ) );

List<RuleEffect> ruleEffects = ruleEngineBuilder.build().evaluate( ruleEvent ).call();

Expand Down Expand Up @@ -342,7 +342,7 @@ RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create(new Date(), "test_program_stage", "test_data_element_one", "-3")), "", null);

List<RuleEffect> ruleEffects = ruleEngineBuilder.events( Arrays.asList( ruleEvent1, ruleEvent2 ) ).build()
List<RuleEffect> ruleEffects = ruleEngineBuilder.events( List.of( ruleEvent1, ruleEvent2 ) ).build()
.evaluate( ruleEvent ).call();

assertEquals( 1 , ruleEffects.size() );
Expand Down Expand Up @@ -375,7 +375,7 @@ RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create(new Date(), "test_program_stage", "test_data_element_one", "-3")), "", null);

List<RuleEffect> ruleEffects = ruleEngineBuilder.events( Arrays.asList( ruleEvent1, ruleEvent2 ) ).build()
List<RuleEffect> ruleEffects = ruleEngineBuilder.events( List.of( ruleEvent1, ruleEvent2 ) ).build()
.evaluate( ruleEvent ).call();

assertEquals( 1 , ruleEffects.size() );
Expand All @@ -399,24 +399,24 @@ public void evaluateD2MaxValueIfVariableName()
.create( null, null, "d2:maxValue(#{" + VARIABLE_NAME + "}) == 8.0", List.of(ruleAction), "", "" );

RuleEngine.Builder ruleEngineBuilder = getRuleEngineBuilder( rule,
Arrays.asList( ruleVariableOne, ruleVariableTwo ) );
List.of( ruleVariableOne, ruleVariableTwo ) );

RuleEvent ruleEvent1 = RuleEvent.create( "test_event1", "test_program_stage1",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "5" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

RuleEvent ruleEvent2 = RuleEvent.create( "test_event2", "test_program_stage2",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "7" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

RuleEvent ruleEvent3 = RuleEvent.create( "test_event3", "test_program_stage3",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "8" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

List<RuleEffect> ruleEffects = ruleEngineBuilder.events( Arrays.asList( ruleEvent1, ruleEvent2 ) ).build()
List<RuleEffect> ruleEffects = ruleEngineBuilder.events( List.of( ruleEvent1, ruleEvent2 ) ).build()
.evaluate( ruleEvent3 ).call();

assertEquals( 1 , ruleEffects.size() );
Expand All @@ -439,24 +439,24 @@ public void evaluateD2MaxValueIfComposedUid()
.create( null, null, "d2:maxValue(#{" + UID01 + "}) == 8.0", List.of(ruleAction), "", "" );

RuleEngine.Builder ruleEngineBuilder = getRuleEngineBuilder( rule,
Arrays.asList( ruleVariableOne, ruleVariableTwo ) );
List.of( ruleVariableOne, ruleVariableTwo ) );

RuleEvent ruleEvent1 = RuleEvent.create( "test_event1", "test_program_stage1",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "5" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

RuleEvent ruleEvent2 = RuleEvent.create( "test_event2", "test_program_stage2",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "7" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

RuleEvent ruleEvent3 = RuleEvent.create( "test_event3", "test_program_stage3",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "8" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

List<RuleEffect> ruleEffects = ruleEngineBuilder.events( Arrays.asList( ruleEvent1, ruleEvent2 ) ).build()
List<RuleEffect> ruleEffects = ruleEngineBuilder.events( List.of( ruleEvent1, ruleEvent2 ) ).build()
.evaluate( ruleEvent3 ).call();

assertEquals( 1 , ruleEffects.size() );
Expand All @@ -478,24 +478,24 @@ public void testMinValueIfVariableName()
Rule rule = Rule.create( null, null, "true", List.of(ruleAction), "", "" );

RuleEngine.Builder ruleEngineBuilder = getRuleEngineBuilder( rule,
Arrays.asList( ruleVariableOne, ruleVariableTwo ) );
List.of( ruleVariableOne, ruleVariableTwo ) );

RuleEvent ruleEvent1 = RuleEvent.create( "test_event1", "test_program_stage1",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "5" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

RuleEvent ruleEvent2 = RuleEvent.create( "test_event2", "test_program_stage2",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "7" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

RuleEvent ruleEvent3 = RuleEvent.create( "test_event3", "test_program_stage3",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "8" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

List<RuleEffect> ruleEffects = ruleEngineBuilder.events( Arrays.asList( ruleEvent1, ruleEvent2 ) ).build()
List<RuleEffect> ruleEffects = ruleEngineBuilder.events( List.of( ruleEvent1, ruleEvent2 ) ).build()
.evaluate( ruleEvent3 ).call();

assertEquals( 1 , ruleEffects.size() );
Expand All @@ -518,24 +518,24 @@ public void testMinValueIfComposedUid()
Rule rule = Rule.create( null, null, "true", List.of(ruleAction), "", "" );

RuleEngine.Builder ruleEngineBuilder = getRuleEngineBuilder( rule,
Arrays.asList( ruleVariableOne, ruleVariableTwo ) );
List.of( ruleVariableOne, ruleVariableTwo ) );

RuleEvent ruleEvent1 = RuleEvent.create( "test_event1", "test_program_stage1",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "5" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

RuleEvent ruleEvent2 = RuleEvent.create( "test_event2", "test_program_stage2",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "7" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

RuleEvent ruleEvent3 = RuleEvent.create( "test_event3", "test_program_stage3",
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, Arrays.asList(
RuleEvent.Status.ACTIVE, new Date(), new Date(), "", null, List.of(
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_one", "8" ),
RuleDataValue.create( new Date(), "test_program_stage", "test_data_element_two", "male" ) ), "", null);

List<RuleEffect> ruleEffects = ruleEngineBuilder.events( Arrays.asList( ruleEvent1, ruleEvent2 ) ).build()
List<RuleEffect> ruleEffects = ruleEngineBuilder.events( List.of( ruleEvent1, ruleEvent2 ) ).build()
.evaluate( ruleEvent3 ).call();

assertEquals( 1 , ruleEffects.size() );
Expand Down
Loading

0 comments on commit 5edc089

Please sign in to comment.