Skip to content

Change JobParameters to HashMap #4327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -58,7 +58,7 @@ public class JobParameters implements Serializable {
* Default constructor.
*/
public JobParameters() {
this.parameters = new LinkedHashMap<>();
this.parameters = new HashMap<>();
}

/**
Expand All @@ -68,7 +68,7 @@ public JobParameters() {
* {@link JobParameter} value.
*/
public JobParameters(Map<String, JobParameter<?>> parameters) {
this.parameters = new LinkedHashMap<>(parameters);
this.parameters = new HashMap<>(parameters);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,9 +21,7 @@
import java.time.LocalTime;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.lang.NonNull;
Expand Down Expand Up @@ -57,7 +55,7 @@ public class JobParametersBuilder {
* Default constructor. Initializes the builder with empty parameters.
*/
public JobParametersBuilder() {
this.parameterMap = new LinkedHashMap<>();
this.parameterMap = new HashMap<>();
}

/**
Expand All @@ -66,7 +64,7 @@ public JobParametersBuilder() {
*/
public JobParametersBuilder(JobExplorer jobExplorer) {
this.jobExplorer = jobExplorer;
this.parameterMap = new LinkedHashMap<>();
this.parameterMap = new HashMap<>();
}

/**
Expand All @@ -85,7 +83,7 @@ public JobParametersBuilder(JobParameters jobParameters) {
*/
public JobParametersBuilder(JobParameters jobParameters, JobExplorer jobExplorer) {
this.jobExplorer = jobExplorer;
this.parameterMap = new LinkedHashMap<>(jobParameters.getParameters());
this.parameterMap = new HashMap<>(jobParameters.getParameters());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 the original author or authors.
* Copyright 2008-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,23 +15,16 @@
*/
package org.springframework.batch.core;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;

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

import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.job.SimpleJob;
import org.springframework.batch.core.launch.support.RunIdIncrementer;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.*;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -121,31 +114,27 @@ void testCopy() {
}

@Test
void testOrderedTypes() {
void testNotOrderedTypes() {
this.parametersBuilder.addDate("SCHEDULE_DATE", date);
this.parametersBuilder.addLong("LONG", 1L);
this.parametersBuilder.addString("STRING", "string value");
Iterator<String> parameters = this.parametersBuilder.toJobParameters().getParameters().keySet().iterator();
assertEquals("SCHEDULE_DATE", parameters.next());
assertEquals("LONG", parameters.next());
assertEquals("STRING", parameters.next());
Set<String> parameters = this.parametersBuilder.toJobParameters().getParameters().keySet();
assertThat(parameters).containsExactlyInAnyOrder("STRING", "LONG", "SCHEDULE_DATE");
}

@Test
void testOrderedStrings() {
void testNotOrderedStrings() {
this.parametersBuilder.addString("foo", "value foo");
this.parametersBuilder.addString("bar", "value bar");
this.parametersBuilder.addString("spam", "value spam");
Iterator<String> parameters = this.parametersBuilder.toJobParameters().getParameters().keySet().iterator();
assertEquals("foo", parameters.next());
assertEquals("bar", parameters.next());
assertEquals("spam", parameters.next());
Set<String> parameters = this.parametersBuilder.toJobParameters().getParameters().keySet();
assertThat(parameters).containsExactlyInAnyOrder("foo","bar","spam");
}

@Test
void testAddJobParameter() {
JobParameter jobParameter = new JobParameter("bar", String.class);
this.parametersBuilder.addParameter("foo", jobParameter);
this.parametersBuilder.addJobParameter("foo", jobParameter);
Map<String, JobParameter<?>> parameters = this.parametersBuilder.toJobParameters().getParameters();
assertEquals(1, parameters.size());
assertEquals("bar", parameters.get("foo").getValue());
Expand Down