Package controller

Source Code of controller.ControllerTest$ControllerB

package controller;

import javax.swing.JComponent;

import junit.framework.Assert;

import org.japura.Application;
import org.japura.controller.Context;
import org.japura.controller.Controller;
import org.japura.controller.ControllerException;
import org.japura.controller.DefaultController;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class ControllerTest{

  @Rule
  public ExpectedException thrown = ExpectedException.none();

  public static class ControllerA extends DefaultController<JComponent>{

  public ControllerA() {
    this(null, null);
  }

  public ControllerA(Context context, Controller parentController) {
    super(context, parentController);
  }

  @Override
  public boolean isComponentInstancied() {
    return false;
  }

  @Override
  protected JComponent getComponent() {
    return null;
  }

  }

  public static class ControllerB extends DefaultController<JComponent>{

  public ControllerB(Context context, Controller parentController) {
    super(context, parentController);
  }

  @Override
  public boolean isComponentInstancied() {
    return false;
  }

  @Override
  protected JComponent getComponent() {
    return null;
  }

  }

  @Before
  public void init() {
  Application.reset();
  }

  @Test
  public void defaultConstructorTest() {
  Context mainContext = Context.getMainContext();

  ControllerA controller = new ControllerA();
  Assert.assertEquals(true, mainContext.equals(controller.getContext()));
  Assert.assertNotNull(controller.getGroup());
  Assert.assertNull(controller.getParent());
  }

  @Test
  public void sameGroupDifContextsTest() {
  thrown.expect(ControllerException.class);

  Context mainContext = Context.getMainContext();
  Context newContext = new Context("NEW CONTEXT");

  ControllerA root = new ControllerA(newContext, null);
  new ControllerA(mainContext, root);
  }

  @Test
  public void childTest() {
  ControllerA parent = new ControllerA();
  ControllerB child = parent.createChild(ControllerB.class);
  Assert.assertEquals(true, child.getParent().equals(parent));
  Assert.assertEquals(true, child.getGroup().equals(parent.getGroup()));
  Assert.assertEquals(true, child.getRoot().equals(parent));
  Assert.assertEquals(true, parent.getChild(ControllerB.class).equals(child));
  Assert.assertEquals(true,
    parent.getChild(child.getControllerId()).equals(child));
  Assert.assertEquals(true, parent.containsChild(ControllerB.class));
  Assert.assertEquals(false, parent.containsChild(ControllerA.class));
  Assert.assertEquals(1, parent.getChildren().size());
  }

  @Test
  public void registerMessageTest() {
  ControllerA c = new ControllerA();
  Assert.assertEquals(1, Application.getMessageManager().getSize());
  c.free();
  Assert.assertEquals(0, Application.getMessageManager().getSize());
  }
}
TOP

Related Classes of controller.ControllerTest$ControllerB

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.