@Test public void When_Illegal_With_Default_Value_Then_Get_Default() throws NoSuchMethodException { Method method = Providers.class .getDeclaredMethod("checkDefaults", String.class); Enum annotation = (Enum) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<Enum> metadata = new Metadata<>(Providers.class, method, null, annotation, type); String result = String .valueOf(enumMockery.illegal(metadata)); assertThat(result, is("illegal")); }
@Test public void When_Call_Illegal_Then_Defer_To_Optional_Mockery() throws NoSuchMethodException { Method method = Providers.class .getDeclaredMethod("object", String.class); Enum annotation = (Enum) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<Enum> metadata = new Metadata<>(Providers.class, method, null, annotation, type); String legal = (String) enumMockery.illegal(metadata); assertTrue(legal.isEmpty()); }
@Test public void When_Call_Illegal_Primitive_Then_Defer_To_Optional_Mockery() throws NoSuchMethodException { Method method = Providers.class .getDeclaredMethod("primitive", int.class); Enum annotation = (Enum) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<Enum> metadata = new Metadata<>(Providers.class, method, null, annotation, type); int legal = (int) enumMockery.illegal(metadata); assertThat(legal, is(0)); }
@Test public void When_Not_Pass_Validation_Then_Throw_Assertion_Error() throws NoSuchMethodException { Method method = Providers.class .getDeclaredMethod("object", String.class); Enum annotation = (Enum) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<Enum> metadata = new Metadata<>(Providers.class, method, null, annotation, type); try { String illegal = (String) enumMockery.illegal(metadata); enumMockery.validate(metadata, illegal); fail(); } catch (AssertionError e) { assertThat(e.getMessage(), is("empty not matches with any of specified values: " + "[asc, desc, sort, random]")); } }
@Test public void When_Empty_Array_Then_Throw_Exception() throws NoSuchMethodException { Method method = Providers.class .getDeclaredMethod("emptyArray", String.class); Enum annotation = (Enum) method.getParameterAnnotations()[0][0]; Type type = method.getGenericParameterTypes()[0]; Metadata<Enum> metadata = new Metadata<>(Providers.class, method, null, annotation, type); String errorMessage = Messages .emptyEnumArray(Providers.class, method); try { enumMockery.legal(metadata); fail(); } catch (RuntimeException e) { assertThat(e.getMessage(), is(errorMessage)); } try { enumMockery.illegal(metadata); fail(); } catch (RuntimeException e) { assertThat(e.getMessage(), is(errorMessage)); } try { enumMockery.validate(metadata, "no matter"); fail(); } catch (RuntimeException e) { assertThat(e.getMessage(), is(errorMessage)); } }