package org.smoothbuild.lang.function.nativ; import static org.smoothbuild.lang.function.base.Name.name; import static org.smoothbuild.lang.function.nativ.NativeFunctionFactory.nativeFunctions; import static org.smoothbuild.lang.function.nativ.TestingUtils.function; import static org.smoothbuild.testing.common.ExceptionMatcher.exception; import static org.testory.Testory.thenReturned; import static org.testory.Testory.thenThrown; import static org.testory.Testory.when; import org.junit.Test; import org.smoothbuild.lang.plugin.Container; import org.smoothbuild.lang.plugin.SmoothFunction; import org.smoothbuild.lang.value.SString; import com.google.common.hash.HashCode; public class NativeFunctionNameTest { @Test public void method_with_name_that_is_illegal_smooth_name_causes_exception() throws Exception { when(() -> nativeFunctions(IllegalFunctionName.class, HashCode.fromInt(13))); thenThrown(exception(new NativeFunctionImplementationException(IllegalFunctionName.class .getMethod("illegal_$_name", Container.class), "Its name illegal_$_name is illegal."))); } public static class IllegalFunctionName { @SmoothFunction public static SString illegal_$_name(Container container) { return null; } } @Test public void function_name_is_equal_to_method_name() throws Exception { when(function(SimpleFunction.class).name()); thenReturned(name("myFunction")); } public static class SimpleFunction { @SmoothFunction public static SString myFunction(Container container) { return null; } } }