Skip to content
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

Remove double brace initialization #3868

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2021 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 Down Expand Up @@ -218,7 +218,6 @@ public Properties getStepArtifactProperties(String stepName, String artifactName
*
* @param properties the step artifact {@link Properties} to add
*/
@SuppressWarnings("serial")
public void setStepArtifactProperties(Map<String, Map<String, Properties>> properties) {
Assert.notNull(properties, "Step artifact properties cannot be null");

Expand All @@ -232,12 +231,10 @@ public void setStepArtifactProperties(Map<String, Map<String, Properties>> prope
Map<String, Properties> artifactProperties = stepArtifactProperties.get(stepName);

if (artifactProperties == null) {
stepArtifactProperties.put(stepName, new HashMap<String, Properties>() {{
put(artifactName, props);
}});
} else {
artifactProperties.put(artifactName, props);
artifactProperties = new HashMap<>();
stepArtifactProperties.put(stepName, artifactProperties);
}
artifactProperties.put(artifactName, props);
}
}
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 the original author or authors.
* Copyright 2013-2021 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 @@ -17,6 +17,7 @@

import static org.junit.Assert.assertEquals;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
Expand Down Expand Up @@ -65,25 +66,19 @@ public void setUp() {
stepArtifactProperties.setProperty("readerProperty1", "readerProperty1value");
stepArtifactProperties.setProperty("readerProperty2", "readerProperty2value");

this.stepArtifactProperties.put("step1", new HashMap<String, Properties>() {{
put("reader", stepArtifactProperties);
}});
this.stepArtifactProperties.put("step1", Collections.singletonMap("reader", stepArtifactProperties));

final Properties partitionProperties = new Properties();
partitionProperties.setProperty("writerProperty1", "writerProperty1valuePartition0");
partitionProperties.setProperty("writerProperty2", "writerProperty2valuePartition0");

this.partitionProperties.put("step2:partition0", new HashMap<String, Properties>() {{
put("writer", partitionProperties);
}});
this.partitionProperties.put("step2:partition0", Collections.singletonMap("writer", partitionProperties));

final Properties partitionStepProperties = new Properties();
partitionStepProperties.setProperty("writerProperty1Step", "writerProperty1");
partitionStepProperties.setProperty("writerProperty2Step", "writerProperty2");

this.partitionProperties.put("step2", new HashMap<String, Properties>() {{
put("writer", partitionStepProperties);
}});
this.partitionProperties.put("step2", Collections.singletonMap("writer", partitionStepProperties));
}

@Test
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2021 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,7 +15,7 @@
*/
package org.springframework.batch.core.step.builder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

Expand Down Expand Up @@ -58,7 +58,6 @@
* @author Mahmoud Ben Hassine
*
*/
@SuppressWarnings("serial")
public class StepBuilderTests {

@Test
Expand Down Expand Up @@ -180,15 +179,10 @@ public void testItemListeners() throws Exception {
jobRepository.add(execution);
PlatformTransactionManager transactionManager = new ResourcelessTransactionManager();

List<String> items = new ArrayList<String>() {{
add("1");
add("2");
add("3");
}};
List<String> items = Arrays.asList("1", "2", "3");

ItemReader<String> reader = new ListItemReader<>(items);

@SuppressWarnings("unchecked")
SimpleStepBuilder<String, String> builder = new StepBuilder("step")
.repository(jobRepository)
.transactionManager(transactionManager)
Expand Down Expand Up @@ -219,16 +213,11 @@ public void testFunctions() throws Exception {
jobRepository.add(execution);
PlatformTransactionManager transactionManager = new ResourcelessTransactionManager();

List<Long> items = new ArrayList<Long>() {{
add(1L);
add(2L);
add(3L);
}};
List<Long> items = Arrays.asList(1L, 2L, 3L);

ItemReader<Long> reader = new ListItemReader<>(items);

ListItemWriter<String> itemWriter = new ListItemWriter<>();
@SuppressWarnings("unchecked")
SimpleStepBuilder<Object, String> builder = new StepBuilder("step")
.repository(jobRepository)
.transactionManager(transactionManager)
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2021 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 @@ -16,6 +16,7 @@
package org.springframework.batch.item.data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -198,12 +199,9 @@ public void testQueryWithHint() {
assertEquals("{ $natural : 1}", query.getHint());
}

@SuppressWarnings("serial")
@Test
public void testQueryWithParameters() {
reader.setParameterValues(new ArrayList<Object>(){{
add("foo");
}});
reader.setParameterValues(Collections.singletonList("foo"));

reader.setQuery("{ name : ?0 }");
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
Expand All @@ -219,12 +217,9 @@ public void testQueryWithParameters() {
assertEquals("{\"name\": -1}", query.getSortObject().toJson());
}

@SuppressWarnings("serial")
@Test
public void testQueryWithCollection() {
reader.setParameterValues(new ArrayList<Object>(){{
add("foo");
}});
reader.setParameterValues(Collections.singletonList("foo"));

reader.setQuery("{ name : ?0 }");
reader.setCollection("collection");
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2021 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 @@ -16,6 +16,7 @@
package org.springframework.batch.item.data;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -57,7 +58,6 @@
* @author Parikshit Dutta
* @author Mahmoud Ben Hassine
*/
@SuppressWarnings("serial")
public class MongoItemWriterTests {

private MongoItemWriter<Object> writer;
Expand Down Expand Up @@ -101,10 +101,7 @@ public void testAfterPropertiesSet() throws Exception {

@Test
public void testWriteNoTransactionNoCollection() throws Exception {
List<Item> items = new ArrayList<Item>() {{
add(new Item("Foo"));
add(new Item("Bar"));
}};
List<Item> items = Arrays.asList(new Item("Foo"), new Item("Bar"));

writer.write(items);

Expand All @@ -114,10 +111,7 @@ public void testWriteNoTransactionNoCollection() throws Exception {

@Test
public void testWriteNoTransactionWithCollection() throws Exception {
List<Object> items = new ArrayList<Object>() {{
add(new Item("Foo"));
add(new Item("Bar"));
}};
List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));

writer.setCollection("collection");

Expand All @@ -137,10 +131,7 @@ public void testWriteNoTransactionNoItems() throws Exception {

@Test
public void testWriteTransactionNoCollection() throws Exception {
final List<Object> items = new ArrayList<Object>() {{
add(new Item("Foo"));
add(new Item("Bar"));
}};
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));

new TransactionTemplate(transactionManager).execute((TransactionCallback<Void>) status -> {
try {
Expand All @@ -158,10 +149,7 @@ public void testWriteTransactionNoCollection() throws Exception {

@Test
public void testWriteTransactionWithCollection() throws Exception {
final List<Object> items = new ArrayList<Object>() {{
add(new Item("Foo"));
add(new Item("Bar"));
}};
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));

writer.setCollection("collection");

Expand All @@ -181,10 +169,7 @@ public void testWriteTransactionWithCollection() throws Exception {

@Test
public void testWriteTransactionFails() throws Exception {
final List<Object> items = new ArrayList<Object>() {{
add(new Item("Foo"));
add(new Item("Bar"));
}};
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));

writer.setCollection("collection");

Expand Down Expand Up @@ -213,10 +198,7 @@ public void testWriteTransactionFails() throws Exception {
*/
@Test
public void testWriteTransactionReadOnly() throws Exception {
final List<Object> items = new ArrayList<Object>() {{
add(new Item("Foo"));
add(new Item("Bar"));
}};
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));

writer.setCollection("collection");

Expand All @@ -242,10 +224,7 @@ public void testWriteTransactionReadOnly() throws Exception {
@Test
public void testRemoveNoObjectIdNoCollection() throws Exception {
writer.setDelete(true);
List<Object> items = new ArrayList<Object>() {{
add(new Item("Foo"));
add(new Item("Bar"));
}};
List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));

writer.write(items);

Expand All @@ -256,10 +235,7 @@ public void testRemoveNoObjectIdNoCollection() throws Exception {
@Test
public void testRemoveNoObjectIdWithCollection() throws Exception {
writer.setDelete(true);
List<Object> items = new ArrayList<Object>() {{
add(new Item("Foo"));
add(new Item("Bar"));
}};
List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));

writer.setCollection("collection");
writer.write(items);
Expand All @@ -271,10 +247,7 @@ public void testRemoveNoObjectIdWithCollection() throws Exception {
@Test
public void testRemoveNoTransactionNoCollection() throws Exception {
writer.setDelete(true);
List<Object> items = new ArrayList<Object>() {{
add(new Item(1));
add(new Item(2));
}};
List<Object> items = Arrays.asList(new Item(1), new Item(2));

writer.write(items);

Expand All @@ -285,10 +258,7 @@ public void testRemoveNoTransactionNoCollection() throws Exception {
@Test
public void testRemoveNoTransactionWithCollection() throws Exception {
writer.setDelete(true);
List<Object> items = new ArrayList<Object>() {{
add(new Item(1));
add(new Item(2));
}};
List<Object> items = Arrays.asList(new Item(1), new Item(2));

writer.setCollection("collection");

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2008 the original author or authors.
* Copyright 2006-2021 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 @@ -16,7 +16,6 @@
package org.springframework.batch.item.database;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.hamcrest.BaseMatcher;
Expand Down Expand Up @@ -131,7 +130,7 @@ public void testWriteAndFlush() throws Exception {
writer.write(Collections.singletonList(new Foo("bar")));
}

@SuppressWarnings({ "rawtypes", "serial", "unchecked" })
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testWriteAndFlushMap() throws Exception {
JdbcBatchItemWriter<Map<String, Object>> mapWriter = new JdbcBatchItemWriter<>();
Expand All @@ -145,14 +144,13 @@ public void testWriteAndFlushMap() throws Exception {
when(namedParameterJdbcOperations.batchUpdate(eq(sql),
captor.capture()))
.thenReturn(new int[] {1});
mapWriter.write(Collections.singletonList(new HashMap<String, Object>() {{put("foo", "bar");}}));
mapWriter.write(Collections.singletonList(Collections.singletonMap("foo", "bar")));

assertEquals(1, captor.getValue().length);
Map<String, Object> results = captor.getValue()[0];
assertEquals("bar", results.get("foo"));
}

@SuppressWarnings({ "rawtypes", "serial", "unchecked" })
@Test
public void testWriteAndFlushMapWithItemSqlParameterSourceProvider() throws Exception {
JdbcBatchItemWriter<Map<String, Object>> mapWriter = new JdbcBatchItemWriter<>();
Expand All @@ -172,7 +170,7 @@ public SqlParameterSource createSqlParameterSource(Map<String, Object> item) {
when(namedParameterJdbcOperations.batchUpdate(any(String.class),
captor.capture()))
.thenReturn(new int[] {1});
mapWriter.write(Collections.singletonList(new HashMap<String, Object>() {{put("foo", "bar");}}));
mapWriter.write(Collections.singletonList(Collections.singletonMap("foo", "bar")));

assertEquals(1, captor.getValue().length);
SqlParameterSource results = captor.getValue()[0];
Expand Down