test/jdk/lambda/MethodReferenceTestInstanceMethod.java

Print this page
rev 7597 : 8015318: Extend Collector with 'finish' operation
Reviewed-by:
Contributed-by: brian.goetz@oracle.com


  30 import org.testng.annotations.Test;
  31 
  32 import static org.testng.Assert.assertEquals;
  33 
  34 @Test(groups = "lib")
  35 public class MethodReferenceTestInstanceMethod {
  36     public Stream<String> generate() {
  37         return Arrays.asList("one", "two", "three", "four", "five", "six")
  38             .stream()
  39             .filter(s->s.length() > 3)
  40             .map(s -> s.toUpperCase());
  41     }
  42 
  43     class Thingy<T,U> {
  44         U blah(Function<T, U> m, T val) {
  45             return m.apply(val);
  46         }
  47     }
  48 
  49     public void testStringBuffer() {
  50         String s = generate().collect(Collectors.toStringBuilder()).toString();
  51         assertEquals(s, "THREEFOURFIVE");
  52     }
  53 
  54     public void testMRInstance() {
  55         Thingy<String,String> t = new Thingy<>();
  56         assertEquals(t.blah(String::toUpperCase, "frogs"), "FROGS");
  57     }
  58 
  59 }


  30 import org.testng.annotations.Test;
  31 
  32 import static org.testng.Assert.assertEquals;
  33 
  34 @Test(groups = "lib")
  35 public class MethodReferenceTestInstanceMethod {
  36     public Stream<String> generate() {
  37         return Arrays.asList("one", "two", "three", "four", "five", "six")
  38             .stream()
  39             .filter(s->s.length() > 3)
  40             .map(s -> s.toUpperCase());
  41     }
  42 
  43     class Thingy<T,U> {
  44         U blah(Function<T, U> m, T val) {
  45             return m.apply(val);
  46         }
  47     }
  48 
  49     public void testStringBuffer() {
  50         String s = generate().collect(Collectors.joining());
  51         assertEquals(s, "THREEFOURFIVE");
  52     }
  53 
  54     public void testMRInstance() {
  55         Thingy<String,String> t = new Thingy<>();
  56         assertEquals(t.blah(String::toUpperCase, "frogs"), "FROGS");
  57     }
  58 
  59 }