Exemplo n.º 1
0
 @Test
 void getOnlyElementWithEmptyCollection() {
   PreconditionViolationException exception =
       expectThrows(
           PreconditionViolationException.class,
           () -> {
             CollectionUtils.getOnlyElement(emptySet());
           });
   assertEquals("collection must contain exactly one element: []", exception.getMessage());
 }
Exemplo n.º 2
0
 @Test
 void getOnlyElementWithMultiElementCollection() {
   PreconditionViolationException exception =
       expectThrows(
           PreconditionViolationException.class,
           () -> {
             CollectionUtils.getOnlyElement(asList("foo", "bar"));
           });
   assertEquals("collection must contain exactly one element: [foo, bar]", exception.getMessage());
 }
Exemplo n.º 3
0
 @Test
 void getOnlyElementWithNullCollection() {
   PreconditionViolationException exception =
       expectThrows(
           PreconditionViolationException.class,
           () -> {
             CollectionUtils.getOnlyElement(null);
           });
   assertEquals("collection must not be null", exception.getMessage());
 }