### Question:
CompositeTaskDecorator implements TaskDecorator { @Override public Runnable decorate(Runnable runnable) { Runnable decoratedRunnable = requireNonNull(runnable, "runnable is null"); for (TaskDecorator decorator : decorators) { decoratedRunnable = decorator.decorate(decoratedRunnable); } return decoratedRunnable; } CompositeTaskDecorator(List<TaskDecorator> decorators); @Override Runnable decorate(Runnable runnable);  }### Answer:
@Test void testNoDecorators() { CompositeTaskDecorator underTest = new CompositeTaskDecorator(List.of()); Runnable runnable = () -> { }; Runnable decoratedRunnable = underTest.decorate(runnable); assertEquals(runnable, decoratedRunnable); }
@Test void testOneDecorator() { DoSomething before = mock(DoSomething.class); DoSomething after = mock(DoSomething.class); Runnable runnable = mock(Runnable.class); InOrder inOrder = Mockito.inOrder(before, after, runnable); CompositeTaskDecorator underTest = new CompositeTaskDecorator(List.of(TestDecorator.around(before, after))); Runnable decoratedRunnable = underTest.decorate(runnable); decoratedRunnable.run(); inOrder.verify(before).doSomething(); inOrder.verify(runnable).run(); inOrder.verify(after).doSomething(); }
@Test void testMultipleDecorators() { DoSomething before1 = mock(DoSomething.class); DoSomething after1 = mock(DoSomething.class); DoSomething before2 = mock(DoSomething.class); DoSomething after2 = mock(DoSomething.class); Runnable runnable = mock(Runnable.class); InOrder inOrder = Mockito.inOrder(before1, after1, before2, after2, runnable); CompositeTaskDecorator underTest = new CompositeTaskDecorator(List.of( TestDecorator.around(before1, after1), TestDecorator.around(before2, after2))); Runnable decoratedRunnable = underTest.decorate(runnable); decoratedRunnable.run(); inOrder.verify(before2).doSomething(); inOrder.verify(before1).doSomething(); inOrder.verify(runnable).run(); inOrder.verify(after1).doSomething(); inOrder.verify(after2).doSomething(); }