SignatureDataOperationResolver implements DataOperationResolver { @Override public DataStoreOperation<?, ?, ?> resolve(Method method) { log.info("Trying to resolve the data operation for method " + method + " by going through the previously set up type mappings"); for (TypeMapping<?> mapping : mappings) { final Class<?> type = mapping.getType(); final Method declaration = findMethod(type, method.getName(), method.getParameterTypes()); if (declaration != null) { log.info("Setting the resolution as a method invocation on the previously prepared type mapping"); final Object instance = mapping.getInstance(); return new MethodInvocationDataStoreOperation<>(instance, declaration); } } return null; } SignatureDataOperationResolver(List<TypeMapping<?>> mappings); @Override DataStoreOperation<?, ?, ?> resolve(Method method);  }
@Test public void testLookingForExactMatchViaInterface() throws Exception { final DataStoreOperation<?, ?, ?> operation = resolver.resolve( ProxiedClass.class.getMethod("saySomething", String.class, Double.class)); assertThat(operation, is(notNullValue())); assertThat(operation, is(instanceOf(MethodInvocationDataStoreOperation.class))); final MethodInvocationDataStoreOperation invocationOperation = (MethodInvocationDataStoreOperation) operation; assertThat(invocationOperation.getInstance(), is(instanceOf(SuperInterface.class))); assertThat(invocationOperation.getMethod(), is(SuperInterface.class.getMethod("saySomething", CharSequence.class, Double.class))); }
@Test public void testLookingForExactMatchViaClass() throws Exception { final DataStoreOperation<?, ?, ?> operation = resolver.resolve( ProxiedClass.class.getMethod("saySomething", String.class, Integer.class)); assertThat(operation, is(notNullValue())); assertThat(operation, is(instanceOf(MethodInvocationDataStoreOperation.class))); final MethodInvocationDataStoreOperation invocationOperation = (MethodInvocationDataStoreOperation) operation; assertThat(invocationOperation.getInstance(), is(instanceOf(ChildClass.class))); assertThat(invocationOperation.getMethod(), is(ChildClass.class.getMethod("saySomething", String.class, Integer.class))); }
@Test public void testLookingForMatchViaSuperClassSuperSignature() throws Exception { final DataStoreOperation<?, ?, ?> operation = resolver.resolve( ProxiedClass.class.getMethod("saySomething", String.class, float.class)); assertThat(operation, is(notNullValue())); assertThat(operation, is(instanceOf(MethodInvocationDataStoreOperation.class))); final MethodInvocationDataStoreOperation invocationOperation = (MethodInvocationDataStoreOperation) operation; assertThat(invocationOperation.getInstance(), is(instanceOf(SuperClass.class))); assertThat(invocationOperation.getMethod(), is(SuperClass.class.getMethod("saySomething", CharSequence.class, Number.class))); }
@Test public void testLookingForMaskedMethod() throws Exception { final DataStoreOperation<?, ?, ?> operation = resolver.resolve(ProxiedClass.class.getMethod("doSomething")); assertThat(operation, is(notNullValue())); assertThat(operation, is(instanceOf(MethodInvocationDataStoreOperation.class))); final MethodInvocationDataStoreOperation invocationOperation = (MethodInvocationDataStoreOperation) operation; assertThat(invocationOperation.getInstance(), is(instanceOf(SuperInterface.class))); assertThat(invocationOperation.getMethod(), is(SuperInterface.class.getMethod("doSomething"))); }
@Test public void testLookingForMethodThatDoesNotMatch() throws Exception { final DataStoreOperation<?, ?, ?> resolved = resolver.resolve( ProxiedClass.class.getMethod("saySomething", String.class, Boolean.class)); assertThat(resolved, is(nullValue())); }