From 896f20e1d376fd757b2be0366dc8bb4c380e4146 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 29 Mar 2021 14:37:25 +0100 Subject: [PATCH] Improve diagnostics of ClassPathFileSystemWatcherTests Closes gh-25821 --- .../boot/devtools/classpath/ClassPathChangedEvent.java | 9 ++++++++- .../classpath/ClassPathFileSystemWatcherTests.java | 9 +++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathChangedEvent.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathChangedEvent.java index d29cd1ade7a..7d800ba6178 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathChangedEvent.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/classpath/ClassPathChangedEvent.java @@ -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. @@ -20,6 +20,7 @@ import java.util.Set; import org.springframework.boot.devtools.filewatch.ChangedFiles; import org.springframework.context.ApplicationEvent; +import org.springframework.core.style.ToStringCreator; import org.springframework.util.Assert; /** @@ -64,4 +65,10 @@ public class ClassPathChangedEvent extends ApplicationEvent { return this.restartRequired; } + @Override + public String toString() { + return new ToStringCreator(this).append("changeSet", this.changeSet) + .append("restartRequired", this.restartRequired).toString(); + } + } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileSystemWatcherTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileSystemWatcherTests.java index d98bec67647..1bd8ba26faa 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileSystemWatcherTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/classpath/ClassPathFileSystemWatcherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 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. @@ -27,6 +27,7 @@ import java.util.Map; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.springframework.boot.devtools.filewatch.ChangedFile; import org.springframework.boot.devtools.filewatch.FileSystemWatcher; import org.springframework.boot.devtools.filewatch.FileSystemWatcherFactory; import org.springframework.context.ApplicationListener; @@ -79,9 +80,9 @@ class ClassPathFileSystemWatcherTests { } Thread.sleep(500); } - assertThat(events.size()).isEqualTo(1); - assertThat(events.get(0).getChangeSet().iterator().next().getFiles().iterator().next().getFile()) - .isEqualTo(classFile); + assertThat(events).hasSize(1); + assertThat(events.get(0).getChangeSet().iterator().next()).extracting(ChangedFile::getFile) + .containsExactly(classFile); context.close(); }