Package net.azib.ipscan

Source Code of net.azib.ipscan.MainTest

package net.azib.ipscan;

import net.azib.ipscan.config.Labels;
import net.azib.ipscan.feeders.FeederException;
import org.junit.Test;

import java.util.logging.Handler;
import java.util.logging.LogRecord;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class MainTest {

  @Test
  public void getLocalizedMessage() {
    // unknown exception
    final boolean wasStackTraceLogged[] = {false};
    Throwable e = new Exception("hello, test!");
    Main.LOG.setUseParentHandlers(false);
    Main.LOG.addHandler(new Handler() {
      public void close() throws SecurityException {
      }
      public void flush() {
      }
      public void publish(LogRecord record) {
        wasStackTraceLogged[0] = true;
      }
    });
    assertEquals(e.toString(), Main.getLocalizedMessage(e));
    assertTrue(wasStackTraceLogged[0]);
   
    // localized exception
    assertEquals(Labels.getLabel("exception.FeederException.malformedIP"),
        Main.getLocalizedMessage(new FeederException("malformedIP")));
   
    // message-less localized exception
    assertEquals(Labels.getLabel("exception.OutOfMemoryError"),
        Main.getLocalizedMessage(new OutOfMemoryError()));
  }
}
TOP

Related Classes of net.azib.ipscan.MainTest

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.