summaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-01-15 11:10:10 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-01-20 13:27:34 +0100
commit275dafcd9f4911c3d71d3dc7b86d68e62f06f86a (patch)
tree6058df1e78cdeea8a86ba408d845f98d57ed9427 /sonar-plugin-api/src/test
parent9030b566aa37558726e14138c292326f93699f8f (diff)
downloadsonarqube-275dafcd9f4911c3d71d3dc7b86d68e62f06f86a.tar.gz
sonarqube-275dafcd9f4911c3d71d3dc7b86d68e62f06f86a.zip
SONAR-6056 API: closeable components must be closed when stopping picocontainer
Diffstat (limited to 'sonar-plugin-api/src/test')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/platform/ComponentContainerTest.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/platform/ComponentContainerTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/platform/ComponentContainerTest.java
index 4135639a877..44660bf61c7 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/platform/ComponentContainerTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/platform/ComponentContainerTest.java
@@ -288,6 +288,37 @@ public class ComponentContainerTest {
assertThat(component.stopped).isTrue();
}
+ /**
+ * Method close() must be called even if the methods start() or stop()
+ * are not defined.
+ */
+ @Test
+ public void should_close_components_without_lifecycle() throws Exception {
+ ComponentContainer container = new ComponentContainer();
+ CloseableComponent component = new CloseableComponent();
+ container.add(component);
+
+ container.execute();
+
+ assertThat(component.isClosed).isTrue();
+ }
+
+ /**
+ * Method close() must be executed after stop()
+ */
+ @Test
+ public void should_close_components_with_lifecycle() throws Exception {
+ ComponentContainer container = new ComponentContainer();
+ StartableCloseableComponent component = new StartableCloseableComponent();
+ container.add(component);
+
+ container.execute();
+
+ assertThat(component.isStopped).isTrue();
+ assertThat(component.isClosed).isTrue();
+ assertThat(component.isClosedAfterStop).isTrue();
+ }
+
public static class StartableComponent {
public boolean started = false, stopped = false;
@@ -333,4 +364,27 @@ public class ComponentContainerTest {
return new SimpleComponent();
}
}
+
+ public static class CloseableComponent implements AutoCloseable {
+ public boolean isClosed = false;
+
+ @Override
+ public void close() throws Exception {
+ isClosed = true;
+ }
+ }
+
+ public static class StartableCloseableComponent implements AutoCloseable {
+ public boolean isClosed = false, isStopped = false, isClosedAfterStop = false;
+
+ public void stop() {
+ isStopped = true;
+ }
+
+ @Override
+ public void close() throws Exception {
+ isClosed = true;
+ isClosedAfterStop = isStopped;
+ }
+ }
}