1 package com.atlassian.util.concurrent;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertSame;
5
6 import org.junit.Test;
7
8 public class FunctionsTest {
9 @Test
10 public void fromSupplier() {
11 final Supplier<Integer> supplier = new Supplier<Integer>() {
12 int count = 0;
13
14 public Integer get() {
15 return count++;
16 }
17 };
18 final Function<String, Integer> function = Functions.fromSupplier(supplier);
19 assertEquals(Integer.valueOf(0), function.get("some"));
20 assertEquals(Integer.valueOf(1), supplier.get());
21 }
22
23 @Test(expected = IllegalArgumentException.class)
24 public void fromSupplierNotNull() {
25 Functions.fromSupplier(null);
26 }
27
28 @Test
29 public void identity() {
30 final Function<String, String> function = Functions.identity();
31 assertSame("same", function.get("same"));
32 }
33 }