/** Method: addToFile(LinkedList<GameNode> g) */
  @Test
  public void testAddToFile() throws Exception {
    GameNode testGameNode = new GameNode();
    testGameNode.setPlayer("rarry");
    testGameNode.setOpponent("lobertie");
    testGameNode.setGameName("raddle");
    testGameNode.setWinLose(true);
    testGameNode.setScore(29);
    LinkedList<GameNode> testLLGN = new LinkedList<GameNode>();
    testLLGN.add(testGameNode);
    testScoreboard.addToFile(testLLGN);

    LinkedList<GameNode> temp = new LinkedList<GameNode>();
    ObjectInputStream i = null;
    try {
      i = new ObjectInputStream(new FileInputStream("gameStats.ser"));
      temp = (LinkedList<GameNode>) i.readObject();
      i.close();
    } catch (FileNotFoundException e) {

    } catch (IOException e) {

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }

    assertTrue(
        "The Object read from file contains the testGameNode added to file",
        temp.contains(testGameNode));
  }
Ejemplo n.º 2
0
  public void testSerial() {
    assertTrue(_nbhm.isEmpty());
    final String k1 = "k1";
    final String k2 = "k2";
    assertThat(_nbhm.put(k1, "v1"), nullValue());
    assertThat(_nbhm.put(k2, "v2"), nullValue());

    // Serialize it out
    try {
      FileOutputStream fos = new FileOutputStream("NBHM_test.txt");
      ObjectOutputStream out = new ObjectOutputStream(fos);
      out.writeObject(_nbhm);
      out.close();
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    // Read it back
    try {
      File f = new File("NBHM_test.txt");
      FileInputStream fis = new FileInputStream(f);
      ObjectInputStream in = new ObjectInputStream(fis);
      NonBlockingIdentityHashMap nbhm = (NonBlockingIdentityHashMap) in.readObject();
      in.close();
      assertThat(
          "serialization works",
          nbhm.toString(),
          anyOf(is("{k1=v1, k2=v2}"), is("{k2=v2, k1=v1}")));
      if (!f.delete()) throw new IOException("delete failed");
    } catch (IOException ex) {
      ex.printStackTrace();
    } catch (ClassNotFoundException ex) {
      ex.printStackTrace();
    }
  }
 public void testExceptionHandling() {
   final ComponentAdapter componentAdapter =
       new ThreadLocalizing.ThreadLocalized(
           new ConstructorInjection.ConstructorInjector(
               TargetInvocationExceptionTester.class, ThrowingComponent.class, null));
   final TargetInvocationExceptionTester tester =
       (TargetInvocationExceptionTester)
           componentAdapter.getComponentInstance(null, ComponentAdapter.NOTHING.class);
   try {
     tester.throwsCheckedException();
     fail("ClassNotFoundException expected");
   } catch (final ClassNotFoundException e) {
     assertEquals("junit", e.getMessage());
   }
   try {
     tester.throwsRuntimeException();
     fail("RuntimeException expected");
   } catch (final RuntimeException e) {
     assertEquals("junit", e.getMessage());
   }
   try {
     tester.throwsError();
     fail("Error expected");
   } catch (final Error e) {
     assertEquals("junit", e.getMessage());
   }
 }
  protected KieServicesClient createDefaultClient() {
    Set<Class<?>> extraClasses = new HashSet<Class<?>>();
    try {
      extraClasses.add(Class.forName("org.jbpm.data.Person", true, kieContainer.getClassLoader()));
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    KieServicesClient kieServicesClient = null;
    if (TestConfig.isLocalServer()) {
      KieServicesConfiguration localServerConfig =
          KieServicesFactory.newRestConfiguration(TestConfig.getHttpUrl(), null, null)
              .setMarshallingFormat(marshallingFormat);

      localServerConfig.addJaxbClasses(extraClasses);
      kieServicesClient =
          KieServicesFactory.newKieServicesClient(localServerConfig, kieContainer.getClassLoader());
    } else {
      configuration.setMarshallingFormat(marshallingFormat);
      configuration.addJaxbClasses(extraClasses);
      configuration.setUserName("Administrator");
      kieServicesClient =
          KieServicesFactory.newKieServicesClient(configuration, kieContainer.getClassLoader());
    }
    configuration.setTimeout(5000);
    setupClients(kieServicesClient);

    return kieServicesClient;
  }
Ejemplo n.º 5
0
  /** Read (say, deserialize) a company */
  public static Company readCompany(String filename) {

    Object o = null;

    try {
      FileInputStream fis = new FileInputStream(filename);
      ObjectInputStream in = new ObjectInputStream(fis);
      o = in.readObject();
      in.close();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      e.printStackTrace();
    }
    return (Company) o;
  }
  /** @throws java.lang.Exception */
  @Before
  public void setUp() throws Exception {

    try {
      for (javax.swing.UIManager.LookAndFeelInfo info :
          javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException nfe) {
      nfe.printStackTrace();

    } catch (javax.swing.UnsupportedLookAndFeelException ulfe) {
      ulfe.printStackTrace();
    }
  }
Ejemplo n.º 7
0
  /** Test of setRect method, of class com.sun.electric.database.geometry.ERectangle. */
  @Test
  public void testSerialization() {
    try {
      ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
      ObjectOutputStream out = new ObjectOutputStream(byteStream);
      out.writeObject(rect);
      out.close();
      byte[] serializedRect = byteStream.toByteArray();

      ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serializedRect));
      ERectangle r = (ERectangle) in.readObject();
      in.close();

      assertEquals(rect, r);
    } catch (IOException e) {
      fail(e.getMessage());
    } catch (ClassNotFoundException e) {
      fail(e.getMessage());
    }
  }
Ejemplo n.º 8
0
  /** Test of execute method, of class HeightMapUpdate. */
  @Test
  public void testExecute() {
    System.out.println("execute");
    HeightMapUpdate instance = null;
    com.novusradix.JavaPop.Server.HeightMap serverh;
    com.novusradix.JavaPop.Client.HeightMap clienth;
    serverh = new com.novusradix.JavaPop.Server.HeightMap(new Dimension(128, 128));
    clienth = new com.novusradix.JavaPop.Client.HeightMap(new Dimension(128, 128), null);

    serverh.up(0, 0);
    serverh.up(0, 0);
    serverh.up(5, 5);
    serverh.up(106, 7);
    serverh.up(106, 7);
    serverh.up(106, 7);
    serverh.up(106, 7);

    serverh.up(112, 25);
    serverh.up(112, 25);

    serverh.up(112, 125);
    serverh.up(112, 125);
    serverh.up(127, 127);
    serverh.up(127, 127);
    serverh.setTile(0, 0, Tile.BASALT);
    serverh.setTile(126, 126, Tile.BURNT);

    instance = serverh.GetUpdate();
    try {
      FileOutputStream fo;
      fo = new FileOutputStream("HeightMapUpdateTest.dat");
      ObjectOutputStream oos;

      oos = new ObjectOutputStream(fo);

      oos.writeObject(instance);
      oos.close();
      fo.close();

      instance = null;

      FileInputStream fi = new FileInputStream("HeightMapUpdateTest.dat");
      ObjectInputStream ois = new ObjectInputStream(fi);

      instance = (HeightMapUpdate) ois.readObject();
      ois.close();
      fi.close();
    } catch (ClassNotFoundException ex) {
      fail(ex.getLocalizedMessage());
    } catch (FileNotFoundException ex) {
      fail(ex.getLocalizedMessage());
    } catch (IOException ex) {
      fail(ex.getLocalizedMessage());
    }

    instance.clientMap = clienth;

    instance.texture = new HashMap<Integer, Byte>();
    instance.execute();
    assertTrue(clienth.getHeight(0, 0) == 2);
    assertTrue(clienth.getHeight(5, 5) == 1);
    assertTrue(clienth.getHeight(106, 7) == 4);
    assertTrue(clienth.getHeight(112, 25) == 2);
    assertTrue(clienth.getHeight(112, 125) == 2);
  }