Search in sources :

Example 1 with FBasicTypeId

use of org.franca.core.franca.FBasicTypeId in project joynr by bmwcarit.

the class AbstractTypeUtilTest method testMultipleOutParameters.

@Test
public void testMultipleOutParameters() throws Exception {
    URL fixtureURL = AbstractTypeUtilTest.class.getResource("MultipleOutParameters.fidl");
    ModelLoader loader = new ModelLoader(fixtureURL.getPath());
    Resource fixtureResource = loader.getResources().iterator().next();
    class MyCallsRealMethods extends CallsRealMethods {

        private static final long serialVersionUID = 1L;

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            if (invocation.getMethod().getName().equals("getTypeName")) {
                Class<?> parameterType0 = invocation.getMethod().getParameterTypes()[0];
                if (parameterType0.equals(FBasicTypeId.class)) {
                    return ((FBasicTypeId) invocation.getArguments()[0]).getName();
                } else if (parameterType0.equals(FType.class)) {
                    return ((FType) invocation.getArguments()[0]).getName();
                } else {
                    return super.answer(invocation);
                }
            } else {
                return super.answer(invocation);
            }
        }
    }
    AbstractTypeUtil typeUtil = mock(AbstractTypeUtil.class, new MyCallsRealMethods());
    Guice.createInjector().injectMembers(typeUtil);
    FModel model = (FModel) fixtureResource.getContents().get(0);
    String stringDatatype = FBasicTypeId.STRING.getName();
    String numberDatatype = FBasicTypeId.INT16.getName();
    String complexDatatype = model.getTypeCollections().get(0).getTypes().get(0).getName();
    FMethod fixture = model.getInterfaces().get(0).getMethods().get(0);
    Iterator<String> result = typeUtil.getTypeNamesForOutputParameter(fixture).iterator();
    assertEquals(result.next(), stringDatatype);
    assertEquals(result.next(), numberDatatype);
    assertEquals(result.next(), complexDatatype);
    assertFalse(result.hasNext());
}
Also used : FType(org.franca.core.franca.FType) FModel(org.franca.core.franca.FModel) Resource(org.eclipse.emf.ecore.resource.Resource) URL(java.net.URL) FBasicTypeId(org.franca.core.franca.FBasicTypeId) ModelLoader(io.joynr.generator.loading.ModelLoader) CallsRealMethods(org.mockito.internal.stubbing.answers.CallsRealMethods) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FMethod(org.franca.core.franca.FMethod) Test(org.junit.Test)

Aggregations

ModelLoader (io.joynr.generator.loading.ModelLoader)1 URL (java.net.URL)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 FBasicTypeId (org.franca.core.franca.FBasicTypeId)1 FMethod (org.franca.core.franca.FMethod)1 FModel (org.franca.core.franca.FModel)1 FType (org.franca.core.franca.FType)1 Test (org.junit.Test)1 CallsRealMethods (org.mockito.internal.stubbing.answers.CallsRealMethods)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1