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()); } }
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 PageController = new Controller(); module.exports = PageController; PageController.show = function() { this.render(); }
static Controller controller; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); controller = new Controller(this); }
public class MyApplication extends Application { @Override public void start(Stage stage) throws Exception { // Just on example how it could be done... Controller controller = new Controller(); MyMainComponent mainComponent = new MyMainComponent(controller); mainComponent.showIn(stage); } public static void main(String[] args) { Application.launch(args); } }
@Test public void testController() { SecurityContext securityContext = Mockito.mock(SecurityContext.class); Authentication authentication = Mockito.mock(Authentication.class); Principal principal1 = Mockito.mock(Principal.class); Principal principal2 = Mockito.mock(Principal.class); Mockito.when(authentication.getPrincipal()).thenReturn(principal1); Mockito.when(securityContext.getAuthentication()).thenReturn(authentication); SecurityContextHolder.setContext(securityContext); new Controller().theMethod(principal2); }
package com.mysuper.sdk; // Public class. public class PublicAPI { // Main method. public static void main(String... args) { int[] numbers = new int[args.length]; for (int i = 0; i < args.length; i++) { numbers[i] = Integer.parseInt(args[i]); } System.out.println(new Controller().translateNumbers(numbers)); } }
private static Controller instance; ... private static void createAndShowGUI() { JFrame frame = new JFrame("MainPanel"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); instance = new Controller(); frame.getContentPane().add(instance); frame.setSize(800, 600); frame.setVisible(true); }
public static void main(String[] args) { // TODO code application logic here Controller controller = new Controller(); controller.initializeSystem(controller); } public void initializeSystem(){ mainWindow = new MainWindow(_controller); mainWindow.setVisible(true); }
... Controller controller = new Controller(); //...do necessary things. int time = controller.getTotalTime(); ...
final Controller c = new Controller(....) ; if(.... ) //manager { if (jRadioButton1.isSelected()) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { MyGUI gui = new MyGUI(c);//pass object c to MyGUI Thread via constructor // gui.setController(c); //or you could have a setter method gui.setVisible(true); }
FXMLLoader loader = new FXMLLoader(); loader.setLocation(this.getClass().getResource("Sample.fxml")); Controller controller = new Controller(); loader.setController(controller); Pane root = loader.load(); Scene scene = new Scene(root);
public void createController(@Observes KubernetesClient client) { //TODO: do something for this cast. kubernetesControllerProducer.set(new Controller(client)); } }
public Controller createController() { Controller controller = new Controller(getKubernetes()); controller.setThrowExceptionOnError(true); return controller; }
public static void main(String[] args) { // TODO code application logic here Controller controller = new Controller(); controller.initializeSystem(); } public void initializeSystem(Controller _controller){ mainWindow = new MainWindow(this); mainWindow.setVisible(true); }
Controller controller = new Controller(); controller.youFunctionForVolleyRequest(email, password, this, loginUrl, new ServerCallback() { @Override public void onSuccess(JSONObject response) { // do stuff here } } );
Model model = new Model(); Controller controller = new Controller(); controller.setModel(model); // or define a constructor taking the model... FXMLLoader loader = new FXMLLoader(getClass().getResource("View.fxml")); loader.getNamespace().put("model", model); loader.setController(controller); Parent root = loader.load();
public class Main { public static void main(String... args){ final Controller appController = new Controller(); final ObjectListModel listModel = new ObjectListModel(); appController.addObserver(listModel); //Event is fired, lists are updated. appController.addObject(new Object()); } }
/** * Returns the created BuildConfig for the given project name and git repository */ public static BuildConfig createAndApplyBuildConfig(KubernetesClient kubernetesClient, String namespace, String projectName, String cloneUrl, Map<String, String> annotations) { BuildConfig buildConfig = createBuildConfig(kubernetesClient, namespace, projectName, cloneUrl, annotations); Controller controller = new Controller(kubernetesClient); controller.setNamespace(namespace); controller.applyBuildConfig(buildConfig, "from project " + projectName); return buildConfig; }