Exemplo n.º 1
0
 public virtual void test_function_fail2()
 {
     System.Func <string, string> a = Unchecked.function((t) =>
     {
         throw new Exception();
     });
     assertThrows(() => a("A"), typeof(Exception));
 }
Exemplo n.º 2
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Converts checked exceptions to unchecked based on the {@code Function} interface.
 /// <para>
 /// This wraps the specified function returning an instance that handles checked exceptions.
 /// If a checked exception is thrown it is converted to an <seealso cref="UncheckedIOException"/>
 /// or <seealso cref="RuntimeException"/> as appropriate.
 ///
 /// </para>
 /// </summary>
 /// @param <T>  the input type of the function </param>
 /// @param <R>  the return type of the function </param>
 /// <param name="function">  the function to be decorated </param>
 /// <returns> the function instance that handles checked exceptions </returns>
 public static System.Func <T, R> function <T, R>(CheckedFunction <T, R> function)
 {
     return((t) =>
     {
         try
         {
             return Unchecked.function(t);
         }
         catch (Exception ex)
         {
             throw propagate(ex);
         }
     });
 }
Exemplo n.º 3
0
 //-------------------------------------------------------------------------
 public virtual void test_function_success()
 {
     System.Func <string, string> a = Unchecked.function((t) => t);
     assertEquals(a("A"), "A");
 }