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

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

This example Akka source code file (MatchBuilderTest.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

a, akka, an, double, expectedexception, integer, japi, match, matchbuildertest, override, rule, test

The MatchBuilderTest.java Akka example source code

/**
 * Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com>
 */

package akka.japi;

import akka.japi.pf.FI;
import akka.japi.pf.Match;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
import org.junit.Test;
import scala.MatchError;

import static org.junit.Assert.*;

public class MatchBuilderTest {

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

  @Test
  public void shouldPassBasicMatchTest() {
    Match<Object, Double> pf = Match.create(Match.match(Integer.class, new FI.Apply<Integer, Double>() {
      @Override
      public Double apply(Integer integer) {
        return integer * 10.0;
      }
    }).match(Number.class, new FI.Apply<Number, Double>() {
      @Override
      public Double apply(Number number) {
        return number.doubleValue() * (-10.0);
      }
    }));

    assertTrue("An integer should be multiplied by 10", new Double(47110).equals(pf.match(new Integer(4711))));
    assertTrue("A double should be multiplied by -10", new Double(-47110).equals(pf.match(new Double(4711))));

    exception.expect(MatchError.class);
    assertFalse("A string should throw a MatchError", new Double(4711).equals(pf.match("4711")));
  }
}

Other Akka source code examples

Here is a short list of links related to this Akka MatchBuilderTest.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.