From ffbc5378351152dfc90daac65d7e7bada9deb65e Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 23 May 2021 18:50:50 +0200 Subject: [PATCH] Polish ConcurrentBeanWrapperTests --- .../beans/ConcurrentBeanWrapperTests.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java b/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java index 34eb559664..d0d3e23327 100644 --- a/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/ConcurrentBeanWrapperTests.java @@ -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"); * 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.IOException; -import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; import java.util.Properties; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; - import static org.assertj.core.api.Assertions.assertThat; /** @@ -38,21 +36,21 @@ import static org.assertj.core.api.Assertions.assertThat; * @author Chris Beams * @since 08.03.2004 */ -public class ConcurrentBeanWrapperTests { +class ConcurrentBeanWrapperTests { private final Log logger = LogFactory.getLog(getClass()); - private Set set = Collections.synchronizedSet(new HashSet()); + private final Set set = ConcurrentHashMap.newKeySet(); private Throwable ex = null; @RepeatedTest(100) - public void testSingleThread() { + void testSingleThread() { performSet(); } @Test - public void testConcurrent() { + void testConcurrent() { for (int i = 0; i < 10; i++) { TestRun run = new TestRun(this); set.add(run); @@ -82,7 +80,7 @@ public class ConcurrentBeanWrapperTests { 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();) { i.next(); @@ -111,7 +109,7 @@ public class ConcurrentBeanWrapperTests { private ConcurrentBeanWrapperTests test; - public TestRun(ConcurrentBeanWrapperTests test) { + TestRun(ConcurrentBeanWrapperTests test) { this.test = test; }