Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *
  *              C E D A R
  *          S O L U T I O N S       "Software done right."
  *           S O F T W A R E
  *
  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *
  * Copyright (c) 2013 Kenneth J. Pronovici.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the Apache License, Version 2.0.
 * See LICENSE for more information about the licensing terms.
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * Author   : Kenneth J. Pronovici <pronovic@ieee.org>
 * Language : Java 6
 * Project  : Common Java Functionality
 *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
package com.cedarsolutions.junit.gwt.classloader;
Specialized translator used to override GWT.create() for stubbed GWT client tests.

This works through the magic of Javassist. Basically, we find the GWT.create() method and replace its body with a call to GwtResourceCreator.create(), which creates all of its resources as Mockito mocks (with some additional logic layered on top to handle certain particular types of interfaces and classes).

This class was derived in part from source code in gwt-test-utils. See README.credits for more information.

Author(s):
Kenneth J. Pronovici <pronovic@ieee.org>
public class GwtCreateTranslator implements Translator {
    private static final String CREATOR = GwtResourceCreator.class.getCanonicalName();
    private static final String GWT = GWT.class.getCanonicalName();
    private static final String METHOD = "create";
    private static final String BODY = "{ return " +  + ".create($1); }";
    @Override
    public void start(ClassPool poolthrows NotFoundExceptionCannotCompileException {
    }
    @Override
    public void onLoad(ClassPool poolString classnamethrows NotFoundExceptionCannotCompileException {
        if (.equals(classname)) {
            CtClass cc = pool.get(classname);
            for (CtMethod method : cc.getMethods()) {
                if (.equals(method.getName())) {
                    method.setBody();
                    return;
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X