Polish ConcurrentBeanWrapperTests

This commit is contained in:
Sam Brannen 2021-05-23 18:50:50 +02:00
parent 9295bcc4a4
commit ffbc537835
1 changed files with 8 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2019 the original author or authors. * Copyright 2002-2021 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,18 +18,16 @@ package org.springframework.beans;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
@ -38,21 +36,21 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Chris Beams * @author Chris Beams
* @since 08.03.2004 * @since 08.03.2004
*/ */
public class ConcurrentBeanWrapperTests { class ConcurrentBeanWrapperTests {
private final Log logger = LogFactory.getLog(getClass()); private final Log logger = LogFactory.getLog(getClass());
private Set<TestRun> set = Collections.synchronizedSet(new HashSet<TestRun>()); private final Set<TestRun> set = ConcurrentHashMap.newKeySet();
private Throwable ex = null; private Throwable ex = null;
@RepeatedTest(100) @RepeatedTest(100)
public void testSingleThread() { void testSingleThread() {
performSet(); performSet();
} }
@Test @Test
public void testConcurrent() { void testConcurrent() {
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
TestRun run = new TestRun(this); TestRun run = new TestRun(this);
set.add(run); set.add(run);
@ -82,7 +80,7 @@ public class ConcurrentBeanWrapperTests {
Properties p = (Properties) System.getProperties().clone(); Properties p = (Properties) System.getProperties().clone();
assertThat(p.size() != 0).as("The System properties must not be empty").isTrue(); assertThat(p).as("The System properties must not be empty").isNotEmpty();
for (Iterator<?> i = p.entrySet().iterator(); i.hasNext();) { for (Iterator<?> i = p.entrySet().iterator(); i.hasNext();) {
i.next(); i.next();
@ -111,7 +109,7 @@ public class ConcurrentBeanWrapperTests {
private ConcurrentBeanWrapperTests test; private ConcurrentBeanWrapperTests test;
public TestRun(ConcurrentBeanWrapperTests test) { TestRun(ConcurrentBeanWrapperTests test) {
this.test = test; this.test = test;
} }