alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Akka/Scala example source code file (JavaAPITestBase.java)

This example Akka source code file (JavaAPITestBase.java) is included in my "Source Code Warehouse" project. The intent of this project is to help you more easily find Akka and Scala source code examples by using tags.

All credit for the original source code belongs to akka.io; I'm just trying to make examples easier to find. (For my Scala work, see my Scala examples and tutorials.)

Akka tags/keywords

actor, akka, callable, event, extendedactorsystem, japi, javaapitestbase, loggingadapter, object, option, serialization, serialize, string, suppresswarnings, test

The JavaAPITestBase.java Akka example source code

package akka.japi;

import akka.actor.ExtendedActorSystem;
import akka.event.LoggingAdapter;
import akka.event.NoLogging;
import akka.serialization.JavaSerializer;
import org.junit.Test;
import java.util.concurrent.Callable;

import static org.junit.Assert.*;

public class JavaAPITestBase {

  @Test
  public void shouldCreateSomeString() {
    Option<String> o = Option.some("abc");
    assertFalse(o.isEmpty());
    assertTrue(o.isDefined());
    assertEquals("abc", o.get());
    assertEquals("abc", o.getOrElse("other"));
  }

  @Test
  public void shouldCreateNone() {
    Option<String> o1 = Option.none();
    assertTrue(o1.isEmpty());
    assertFalse(o1.isDefined());
    assertEquals("other", o1.getOrElse("other"));

    Option<Float> o2 = Option.none();
    assertTrue(o2.isEmpty());
    assertFalse(o2.isDefined());
    assertEquals("other", o1.getOrElse("other"));
  }

  @Test
  public void shouldEnterForLoop() {
    for (@SuppressWarnings("unused")
    String s : Option.some("abc")) {
      return;
    }
    fail("for-loop not entered");
  }

  @Test
  public void shouldNotEnterForLoop() {
    for (@SuppressWarnings("unused")
    Object o : Option.none()) {
      fail("for-loop entered");
    }
  }

  @Test
  public void shouldBeSingleton() {
    assertSame(Option.none(), Option.none());
  }

  @Test
  public void mustBeAbleToGetNoLogging() {
      LoggingAdapter a = NoLogging.getInstance();
      assertNotNull(a);
  }
    
  @Test
  public void mustBeAbleToUseCurrentSystem() {
      assertNull(JavaSerializer.currentSystem().withValue(null, new Callable<ExtendedActorSystem>() {
          public ExtendedActorSystem call() {
              return JavaSerializer.currentSystem().value();
          }
      }));
  }
}

Other Akka source code examples

Here is a short list of links related to this Akka JavaAPITestBase.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.