Class AbstractCollectionAssert<SELF extends AbstractCollectionAssert<SELF,​ACTUAL,​ELEMENT,​ELEMENT_ASSERT>,​ACTUAL extends Collection<? extends ELEMENT>,​ELEMENT,​ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,​ELEMENT>>

    • Constructor Detail

      • AbstractCollectionAssert

        protected AbstractCollectionAssert​(ACTUAL actual,
                                           Class<?> selfType)
    • Method Detail

      • isUnmodifiable

        public SELF isUnmodifiable()
        Verifies that the actual collection is unmodifiable, i.e., throws an UnsupportedOperationException with any attempt to modify the collection.

        Example:

         // assertions will pass
         assertThat(Collections.unmodifiableCollection(new ArrayList<>())).isUnmodifiable();
         assertThat(Collections.unmodifiableList(new ArrayList<>())).isUnmodifiable();
         assertThat(Collections.unmodifiableSet(new HashSet<>())).isUnmodifiable();
        
         // assertions will fail
         assertThat(new ArrayList<>()).isUnmodifiable();
         assertThat(new HashSet<>()).isUnmodifiable();
        Returns:
        this assertion object.
        Throws:
        AssertionError - if the actual collection is modifiable.
        See Also:
        Collections.unmodifiableCollection(Collection), Collections.unmodifiableList(List), Collections.unmodifiableSet(Set)
      • assertIsUnmodifiable

        private void assertIsUnmodifiable()
      • expectUnsupportedOperationException

        private void expectUnsupportedOperationException​(Runnable runnable,
                                                         String method)