Preconditions { public static void checkArgument( boolean expression, String message ) { if ( !expression ) { throw new IllegalArgumentException( message ); } } private  Preconditions(); static void checkArgument( boolean expression, String message ); static void checkArgument( Object argument, Class<?> expectedClass );  }
@Test void shouldCheckBooleanArgument() { assertDoesNotThrow( () -> checkArgument( true, "" ) ); assertDoesNotThrow( () -> checkArgument( !Duration.ofSeconds( 1 ).isZero(), "" ) ); assertThrows( IllegalArgumentException.class, () -> checkArgument( false, "" ) ); assertThrows( IllegalArgumentException.class, () -> checkArgument( Period.ofDays( 2 ).isNegative(), "" ) ); }
@Test void shouldCheckArgumentType() { assertDoesNotThrow( () -> checkArgument( "Hello", String.class ) ); assertDoesNotThrow( () -> checkArgument( new ArrayList<>(), List.class ) ); assertThrows( IllegalArgumentException.class, () -> checkArgument( 42, String.class ) ); assertThrows( IllegalArgumentException.class, () -> checkArgument( new ArrayList<>(), Map.class ) ); }