@Test public void When_Call_Legal_Then_Get_Legal() 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); for (int i = 0; i < 30; i++) { String legal = (String) enumMockery.legal(metadata); enumMockery.validate(metadata, legal); } }
@Test public void When_Pass_Validation_Then_Do_Not_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); String legal = (String) enumMockery.legal(metadata); enumMockery.validate(metadata, legal); }
@Test public void When_Call_Legal_Primitive_Then_Get_Legal() 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); for (int i = 0; i < 30; i++) { int legal = (int) enumMockery.legal(metadata); enumMockery.validate(metadata, legal); } }
@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)); } }