import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.verify; import static org.powermock.api.mockito.PowerMockito.mock; import static org.powermock.api.mockito.PowerMockito.mockStatic; import static org.powermock.api.mockito.PowerMockito.when; @RunWith(PowerMockRunner.class) @PrepareForTest({Controller.class, LoggerFactory.class}) public class ControllerTest { @Test public void name() throws Exception { mockStatic(LoggerFactory.class); Logger logger = mock(Logger.class); when(LoggerFactory.getLogger(any(Class.class))).thenReturn(logger); new Controller().log(); verify(logger).warn(anyString()); } }
@Override public String getReplicationControllerIdForPod(String podId) { ReplicationController replicationController = kubernetes.getReplicationControllerForPod(podId); if (replicationController != null) { return getId(replicationController); } return null; }
public class AnotherClass { Controller controller = new Controller(); public void registerCallBack(callBack back){ controller.registerCallBack(back); } public void show(){ controller.getCallBack().update(1, "show me!"); } }
... Controller controller = new Controller(); //...do necessary things. int time = controller.getTotalTime(); ...
@Test public void testControllerWithPureJUnit(){ Controller controller = new Controller(); //do some mocking if it's needed Response response = controller.fetchStatus(1); //asser the reponse from controller }
public KubernetesClient getKubernetes() { if (kubernetes == null) { kubernetes = new KubernetesClient(); } return kubernetes; }
public KubernetesFactory(String address) { this.address = address; if (isEmpty(address)) { findKubernetesMaster(); } init(); }
public static Map<String, ReplicationControllerSchema> getReplicationControllerMap(Kubernetes kubernetes) { return toReplicationControllerMap(kubernetes.getReplicationControllers()); }
public void setAddress(String address) { this.address = address; if (isEmpty(address)) { findKubernetesMaster(); } }
public static Map<String, ServiceSchema> getServiceMap(Kubernetes kubernetes) { return toServiceMap(kubernetes.getServices()); }
protected AuthenticationMode locateAuthenticationMode() { if (this.authenticationMode != null) { return this.authenticationMode; } if (KubernetesHelper.isOpenShift(kubernetes)) { // Jolokia needs the Bearer token by default on Openshift return AuthenticationMode.BEARER; } return AuthenticationMode.BASIC; }
public static void main(String[] args) { try { for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (Exception e) { // If Nimbus is not available, fall back to cross-platform try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch (Exception ex) { // not worth my time } } new Controller(); }
function Controller() { // local variable var foo = 1; // instance property this.bar = 2; } // imagine Angular creates an instance of your controller like this: var instance = new Controller(); console.log('foo', instance.foo) // undefined console.log('bar', instance.bar) // 2
var Controller = function() { this.reset = function() { console.log('reset'); }; } var controller = new Controller(); document.getElementById("reset").onclick = controller.reset;
var c = new Controller(); // simple example var f = c.getStory; f(); // this.model will probably be undefined // further examples (easy to bump into when working with Node.js callbacks) setTimeout(c.getStory, 100); fs.readFile("/etc/passwd", c.getStory);
static Controller controller; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); controller = new Controller(this); }
GoogleMap mMap; private static Controller instance; private Controller() { } public static Controller getInstance(GoogleMap map) { if (instance == null) { instance = new Controller(); instance.mMap=map; } return instance; }
public class CommonWebConfiguration extends WebMvcConfigurationSupport { @Bean @ConditionalOnProperty(prefix="properties",name = "enabled") public Controller controller() { return new Controller (); } }
public class Main { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new Controller().startChrono(1); } }); } }