  Result generate(final int items, final boolean generateNames) {
    final JBBPDslBuilder builder = JBBPDslBuilder.Begin();

    final List<StructLen> counterStack = new ArrayList<>();
    counterStack.add(new StructLen());

    int structsTotal = 0;
    int fieldsTotal = 0;
    int booleanDataItems = 0;

    int activeStructCounter = 0;

    long typeFlags = 0;

    for (int i = 0; i < items; i++) {

      if (RND.nextInt(50) > 48) {
        builder.ByteOrder(JBBPByteOrder.LITTLE_ENDIAN);
      } else {
        builder.ByteOrder(JBBPByteOrder.BIG_ENDIAN);
      }

      if (activeStructCounter > 0 && RND.nextInt(100) > 90) {
        i--;
        activeStructCounter--;
        builder.CloseStruct();
        final StructLen len = counterStack.remove(0);
        counterStack.get(0).add(len.make());
      } else {
        final int rndType = RND.nextInt(27);
        typeFlags |= (1 << rndType);
        switch (rndType) {
          case 0: { // STRUCT
            builder.Struct(generateNames ? makeRndName() : null);
            counterStack.add(0, new StructLen());
            activeStructCounter++;
            structsTotal++;
          }
          break;
          case 1: { // STRUCT_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.StructArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.add(0, new StructLen(arrayLen));
            activeStructCounter++;
            structsTotal++;
          }
          break;
          case 2: { // BIT
            final JBBPBitNumber bits = makeRndBitNumber();
            builder.Bits(generateNames ? makeRndName() : null, bits);
            counterStack.get(0).add(bits.getBitNumber());
            fieldsTotal++;
          }
          break;
          case 3: { // BIT_ARRAY
            final JBBPBitNumber bits = makeRndBitNumber();
            final int arrayLen = makeArrayLengthNumber();
            builder.BitArray(generateNames ? makeRndName() : null, bits, String.valueOf(arrayLen));
            counterStack.get(0).add(bits.getBitNumber() * arrayLen);
            fieldsTotal++;
          }
          break;
          case 4: { // SKIP
            final int arrayLen = makeArrayLengthNumber();
            final int bitlen;
            if (RND.nextBoolean()) {
              builder.Skip();
              bitlen = 8;
            } else {
              final int len = makeArrayLengthNumber();
              builder.Skip(String.valueOf(len));
              bitlen = len * 8;
            }
            counterStack.get(0).add(bitlen);
          }
          break;
          case 5: { // BOOL
            builder.Bool(generateNames ? makeRndName() : null);
            counterStack.get(0).add(8);
            fieldsTotal++;
            booleanDataItems ++;
          }
          break;
          case 6: { // BOOL_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.BoolArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(8 * arrayLen);
            fieldsTotal++;
            booleanDataItems += arrayLen;
          }
          break;
          case 7: { // BYTE
            builder.Byte(generateNames ? makeRndName() : null);
            counterStack.get(0).add(8);
            fieldsTotal++;
          }
          break;
          case 8: { // BYTE_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.ByteArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(arrayLen * 8);
            fieldsTotal++;
          }
          break;
          case 9: { // UBYTE
            builder.UByte(generateNames ? makeRndName() : null);
            counterStack.get(0).add(8);
            fieldsTotal++;
          }
          break;
          case 10: { // UBYTE_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.UByteArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(8 * arrayLen);
            fieldsTotal++;
          }
          break;
          case 11: { // SHORT
            builder.Short(generateNames ? makeRndName() : null);
            counterStack.get(0).add(16);
            fieldsTotal++;
          }
          break;
          case 12: { // SHORT_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.ShortArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(arrayLen * 16);
            fieldsTotal++;
          }
          break;
          case 13: { // USHORT
            builder.UShort(generateNames ? makeRndName() : null);
            counterStack.get(0).add(16);
            fieldsTotal++;
          }
          break;
          case 14: { // USHORT_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.UShortArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(16 * arrayLen);
            fieldsTotal++;
          }
          break;
          case 15: { // INT
            builder.Int(generateNames ? makeRndName() : null);
            counterStack.get(0).add(32);
            fieldsTotal++;
          }
          break;
          case 16: { // INT_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.IntArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(32 * arrayLen);
            fieldsTotal++;
          }
          break;
          case 17: { // Comment
            builder.Comment(generateComment());
          }
          break;
          case 18: { // LONG
            builder.Long(generateNames ? makeRndName() : null);
            counterStack.get(0).add(64);
            fieldsTotal++;
          }
          break;
          case 19: { // LONG_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.LongArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(arrayLen * 64);
            fieldsTotal++;
          }
          break;
          case 20: { // FLOAT
            builder.Float(generateNames ? makeRndName() : null);
            counterStack.get(0).add(32);
            fieldsTotal++;
          }
          break;
          case 21: { // FLOAT_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.FloatArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(arrayLen * 32);
            fieldsTotal++;
          }
          break;
          case 22: { // DOUBLE
            builder.Double(generateNames ? makeRndName() : null);
            counterStack.get(0).add(64);
            fieldsTotal++;
          }
          break;
          case 23: { // DOUBLE_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.DoubleArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(arrayLen * 64);
            fieldsTotal++;
          }
          break;
          case 24: { // STRUCT END
            if (activeStructCounter > 0) {
              i--;
              activeStructCounter--;
              builder.CloseStruct();
              final StructLen len = counterStack.remove(0);
              counterStack.get(0).add(len.make());
            }
          }
          break;
          case 25: { // COMMENT
            builder.Comment(genRandomString(this.RND.nextInt(32)));
          }
          break;
          case 26: { // COMMENT NEW LINE
            builder.NewLineComment(genRandomString(this.RND.nextInt(32)));
          }
          break;
        }
      }
    }

    while (activeStructCounter > 0) {
      activeStructCounter--;
      builder.CloseStruct();
      final StructLen len = counterStack.remove(0);
      counterStack.get(0).add(len.make());
    }

    return new Result(builder.End(), counterStack.get(0).make(), fieldsTotal, structsTotal, booleanDataItems, typeFlags);
  }

  Result generate(final int items, final boolean generateNames) {
    final JBBPDslBuilder builder = JBBPDslBuilder.Begin();

    final List<StructLen> counterStack = new ArrayList<StructLen>();
    counterStack.add(new StructLen());

    int structsTotal = 0;
    int fieldsTotal = 0;
    int booleanDataItems = 0;

    int activeStructCounter = 0;

    long typeFlags = 0;

    for (int i = 0; i < items; i++) {

      if (RND.nextInt(50) > 48) {
        builder.ByteOrder(JBBPByteOrder.LITTLE_ENDIAN);
      } else {
        builder.ByteOrder(JBBPByteOrder.BIG_ENDIAN);
      }

      if (activeStructCounter > 0 && RND.nextInt(100) > 90) {
        i--;
        activeStructCounter--;
        builder.CloseStruct();
        final StructLen len = counterStack.remove(0);
        counterStack.get(0).add(len.make());
      } else {
        final int rndType = RND.nextInt(27);
        typeFlags |= (1 << rndType);
        switch (rndType) {
          case 0: { // STRUCT
            builder.Struct(generateNames ? makeRndName() : null);
            counterStack.add(0, new StructLen());
            activeStructCounter++;
            structsTotal++;
          }
          break;
          case 1: { // STRUCT_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.StructArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.add(0, new StructLen(arrayLen));
            activeStructCounter++;
            structsTotal++;
          }
          break;
          case 2: { // BIT
            final JBBPBitNumber bits = makeRndBitNumber();
            builder.Bits(generateNames ? makeRndName() : null, bits);
            counterStack.get(0).add(bits.getBitNumber());
            fieldsTotal++;
          }
          break;
          case 3: { // BIT_ARRAY
            final JBBPBitNumber bits = makeRndBitNumber();
            final int arrayLen = makeArrayLengthNumber();
            builder.BitArray(generateNames ? makeRndName() : null, bits, String.valueOf(arrayLen));
            counterStack.get(0).add(bits.getBitNumber() * arrayLen);
            fieldsTotal++;
          }
          break;
          case 4: { // SKIP
            final int arrayLen = makeArrayLengthNumber();
            final int bitlen;
            if (RND.nextBoolean()) {
              builder.Skip();
              bitlen = 8;
            } else {
              final int len = makeArrayLengthNumber();
              builder.Skip(String.valueOf(len));
              bitlen = len * 8;
            }
            counterStack.get(0).add(bitlen);
          }
          break;
          case 5: { // BOOL
            builder.Bool(generateNames ? makeRndName() : null);
            counterStack.get(0).add(8);
            fieldsTotal++;
            booleanDataItems ++;
          }
          break;
          case 6: { // BOOL_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.BoolArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(8 * arrayLen);
            fieldsTotal++;
            booleanDataItems += arrayLen;
          }
          break;
          case 7: { // BYTE
            builder.Byte(generateNames ? makeRndName() : null);
            counterStack.get(0).add(8);
            fieldsTotal++;
          }
          break;
          case 8: { // BYTE_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.ByteArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(arrayLen * 8);
            fieldsTotal++;
          }
          break;
          case 9: { // UBYTE
            builder.UByte(generateNames ? makeRndName() : null);
            counterStack.get(0).add(8);
            fieldsTotal++;
          }
          break;
          case 10: { // UBYTE_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.UByteArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(8 * arrayLen);
            fieldsTotal++;
          }
          break;
          case 11: { // SHORT
            builder.Short(generateNames ? makeRndName() : null);
            counterStack.get(0).add(16);
            fieldsTotal++;
          }
          break;
          case 12: { // SHORT_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.ShortArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(arrayLen * 16);
            fieldsTotal++;
          }
          break;
          case 13: { // USHORT
            builder.UShort(generateNames ? makeRndName() : null);
            counterStack.get(0).add(16);
            fieldsTotal++;
          }
          break;
          case 14: { // USHORT_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.UShortArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(16 * arrayLen);
            fieldsTotal++;
          }
          break;
          case 15: { // INT
            builder.Int(generateNames ? makeRndName() : null);
            counterStack.get(0).add(32);
            fieldsTotal++;
          }
          break;
          case 16: { // INT_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.IntArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(32 * arrayLen);
            fieldsTotal++;
          }
          break;
          case 17: { // Comment
            builder.Comment(generateComment());
          }
          break;
          case 18: { // LONG
            builder.Long(generateNames ? makeRndName() : null);
            counterStack.get(0).add(64);
            fieldsTotal++;
          }
          break;
          case 19: { // LONG_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.LongArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(arrayLen * 64);
            fieldsTotal++;
          }
          break;
          case 20: { // FLOAT
            builder.Float(generateNames ? makeRndName() : null);
            counterStack.get(0).add(32);
            fieldsTotal++;
          }
          break;
          case 21: { // FLOAT_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.FloatArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(arrayLen * 32);
            fieldsTotal++;
          }
          break;
          case 22: { // DOUBLE
            builder.Double(generateNames ? makeRndName() : null);
            counterStack.get(0).add(64);
            fieldsTotal++;
          }
          break;
          case 23: { // DOUBLE_ARRAY
            final int arrayLen = makeArrayLengthNumber();
            builder.DoubleArray(generateNames ? makeRndName() : null, String.valueOf(arrayLen));
            counterStack.get(0).add(arrayLen * 64);
            fieldsTotal++;
          }
          break;
          case 24: { // STRUCT END
            if (activeStructCounter > 0) {
              i--;
              activeStructCounter--;
              builder.CloseStruct();
              final StructLen len = counterStack.remove(0);
              counterStack.get(0).add(len.make());
            }
          }
          break;
          case 25: { // COMMENT
            builder.Comment(genRandomString(this.RND.nextInt(32)));
          }
          break;
          case 26: { // COMMENT NEW LINE
            builder.NewLineComment(genRandomString(this.RND.nextInt(32)));
          }
          break;
        }
      }
    }

    while (activeStructCounter > 0) {
      activeStructCounter--;
      builder.CloseStruct();
      final StructLen len = counterStack.remove(0);
      counterStack.get(0).add(len.make());
    }

    return new Result(builder.End(), counterStack.get(0).make(), fieldsTotal, structsTotal, booleanDataItems, typeFlags);
  }

Replace Generic With Diamond ArrayList<StructLen> with ArrayList<> in method package generate(items int, generateNames boolean) : Result from class com.igormaznitsa.jbbp.compiler.conversion.RandomAutoTest


  @Test
  public void testErrorForIteratorRemove() {
    assertThrows(UnsupportedOperationException.class, () -> new JBBPTokenizer("int a;").remove());
  }

  @Test
  public void testErrorForIteratorRemove() {
    assertThrows(UnsupportedOperationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPTokenizer("int a;").remove();
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.tokenizer.JBBPTokenizerTest.testErrorForIteratorRemove.assertThrows.new Executable with () -> new JBBPTokenizer("int a;").remove() in method public testErrorForIteratorRemove() : void from class com.igormaznitsa.jbbp.compiler.tokenizer.JBBPTokenizerTest


  @Test
  public void testExpression_Error_ConstantsWithoutOperators() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator(" 1   334", null, null));
  }

  @Test
  public void testExpression_Error_ConstantsWithoutOperators() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator(" 1   334", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_ConstantsWithoutOperators.assertThrows.new Executable with () -> new JBBPExpressionEvaluator(" 1   334",null,null) in method public testExpression_Error_ConstantsWithoutOperators() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_OnlyBrackets() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator(" ( ( ( ( ) )) )  ", null, null));
  }

  @Test
  public void testExpression_Error_OnlyBrackets() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator(" ( ( ( ( ) )) )  ", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_OnlyBrackets.assertThrows.new Executable with () -> new JBBPExpressionEvaluator(" ( ( ( ( ) )) )  ",null,null) in method public testExpression_Error_OnlyBrackets() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_NonClosedBracket() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator("(34+45  ", null, null));
  }

  @Test
  public void testExpression_Error_NonClosedBracket() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("(34+45  ", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_NonClosedBracket.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("(34+45  ",null,null) in method public testExpression_Error_NonClosedBracket() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_NonOpenedBracket() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator("34+45)  ", null, null));
  }

  @Test
  public void testExpression_Error_NonOpenedBracket() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("34+45)  ", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_NonOpenedBracket.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("34+45)  ",null,null) in method public testExpression_Error_NonOpenedBracket() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_Spaces() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator("  ", null, null));
  }

  @Test
  public void testExpression_Error_Spaces() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("  ", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_Spaces.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("  ",null,null) in method public testExpression_Error_Spaces() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_Empty() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator("", null, null));
  }

  @Test
  public void testExpression_Error_Empty() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_Empty.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("",null,null) in method public testExpression_Error_Empty() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_OnlyUnaryPlus() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator("+", null, null));
  }

  @Test
  public void testExpression_Error_OnlyUnaryPlus() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("+", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_OnlyUnaryPlus.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("+",null,null) in method public testExpression_Error_OnlyUnaryPlus() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_OnlyUnaryMinus() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator("-", null, null));
  }

  @Test
  public void testExpression_Error_OnlyUnaryMinus() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("-", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_OnlyUnaryMinus.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("-",null,null) in method public testExpression_Error_OnlyUnaryMinus() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_OnlyNot() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator("~", null, null));
  }

  @Test
  public void testExpression_Error_OnlyNot() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("~", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_OnlyNot.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("~",null,null) in method public testExpression_Error_OnlyNot() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_WrongFirstUnaryOperator() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator("%345", null, null));
  }

  @Test
  public void testExpression_Error_WrongFirstUnaryOperator() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("%345", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_WrongFirstUnaryOperator.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("%345",null,null) in method public testExpression_Error_WrongFirstUnaryOperator() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_WrongUnaryOperator() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator("222%%345", null, null));
  }

  @Test
  public void testExpression_Error_WrongUnaryOperator() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("222%%345", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_WrongUnaryOperator.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("222%%345",null,null) in method public testExpression_Error_WrongUnaryOperator() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_OnlyNonUnaryOperator() {
    assertThrows(JBBPCompilationException.class, () -> new JBBPExpressionEvaluator("*", null, null));
  }

  @Test
  public void testExpression_Error_OnlyNonUnaryOperator() {
    assertThrows(JBBPCompilationException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("*", null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_OnlyNonUnaryOperator.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("*",null,null) in method public testExpression_Error_OnlyNonUnaryOperator() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_MulWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("123*", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_Error_MulWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("123*", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_MulWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("123*",null,null).eval(null,0,null,null) in method public testExpression_Error_MulWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_SubWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("123-", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_Error_SubWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("123-", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_SubWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("123-",null,null).eval(null,0,null,null) in method public testExpression_Error_SubWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_AddWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("123+", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_Error_AddWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("123+", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_AddWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("123+",null,null).eval(null,0,null,null) in method public testExpression_Error_AddWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_ModWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("123%", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_Error_ModWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("123%", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_ModWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("123%",null,null).eval(null,0,null,null) in method public testExpression_Error_ModWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_DivWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("123/", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_Error_DivWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("123/", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_DivWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("123/",null,null).eval(null,0,null,null) in method public testExpression_Error_DivWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_AndWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("123&", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_Error_AndWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("123&", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_AndWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("123&",null,null).eval(null,0,null,null) in method public testExpression_Error_AndWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_OrWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("123|", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_Error_OrWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("123|", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_OrWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("123|",null,null).eval(null,0,null,null) in method public testExpression_Error_OrWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_Error_XorWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("123^", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_Error_XorWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("123^", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_Error_XorWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("123^",null,null).eval(null,0,null,null) in method public testExpression_Error_XorWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_LeftShift_ErrorWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("1234<<", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_LeftShift_ErrorWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("1234<<", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_LeftShift_ErrorWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("1234<<",null,null).eval(null,0,null,null) in method public testExpression_LeftShift_ErrorWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_RightShift_ErrorWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("1234 >>", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_RightShift_ErrorWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("1234 >>", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_RightShift_ErrorWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("1234 >>",null,null).eval(null,0,null,null) in method public testExpression_RightShift_ErrorWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_RightSignShift_ErrorWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, () -> new JBBPExpressionEvaluator("1234 >>>", null, null).eval(null, 0, null, null));
  }

  @Test
  public void testExpression_RightSignShift_ErrorWithoutSecondArgument() {
    assertThrows(JBBPEvalException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPExpressionEvaluator("1234 >>>", null, null).eval(null, 0, null, null);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_RightSignShift_ErrorWithoutSecondArgument.assertThrows.new Executable with () -> new JBBPExpressionEvaluator("1234 >>>",null,null).eval(null,0,null,null) in method public testExpression_RightSignShift_ErrorWithoutSecondArgument() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_ReverseByte() {
    JBBPExpressionEvaluator expr = new JBBPExpressionEvaluator("((($v*2050&139536)|($v*32800&558144))*65793>>16)&255", null, null);
    assertEquals(3, expr.getMaxStackDepth());
    assertEquals(JBBPUtils.reverseBitsInByte((byte) 123) & 0xFF, expr.eval(null, 0, null, new JBBPNamedNumericFieldMap((fieldName, numericFieldMap, compiledBlock) -> {
      if ("v".equals(fieldName)) {
        return 123;
      } else {
        fail("Unexpected field [" + fieldName + ']');
        return 0;
      }
    })));
  }

  @Test
  public void testExpression_ReverseByte() {
    JBBPExpressionEvaluator expr = new JBBPExpressionEvaluator("((($v*2050&139536)|($v*32800&558144))*65793>>16)&255", null, null);
    assertEquals(3, expr.getMaxStackDepth());
    assertEquals(JBBPUtils.reverseBitsInByte((byte) 123) & 0xFF, expr.eval(null, 0, null, new JBBPNamedNumericFieldMap(new JBBPExternalValueProvider() {

      @Override
      public int provideArraySize(final String fieldName, final JBBPNamedNumericFieldMap numericFieldMap, final JBBPCompiledBlock compiledBlock) {
        if ("v".equals(fieldName)) {
          return 123;
        } else {
          fail("Unexpected field [" + fieldName + ']');
          return 0;
        }
      }
    })));
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_ReverseByte.assertEquals.eval.new JBBPNamedNumericFieldMap.new JBBPExternalValueProvider with (fieldName, numericFieldMap, compiledBlock) -> {if("v".equals(fieldName)){return 123; in method public testExpression_ReverseByte() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_CheckExternalField() {
    final int value = 1234;
    final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap((fieldName, numericFieldMap, compiledBlock) -> {
      if (fieldName.equals("value")) {
        return value;
      }
      assertNotNull(numericFieldMap);
      assertNotNull(compiledBlock);
      fail("Unexpected request for value [" + fieldName + ']');
      return -1;
    });

    final List<JBBPNamedFieldInfo> list = new ArrayList<>();

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPExpressionEvaluator expr = new JBBPExpressionEvaluator("123*($value-45/3)", list, compiled);
    assertEquals(4, expr.getMaxStackDepth());
    assertEquals(123 * (value - 45 / 3), expr.eval(null, 0, compiledBlock, map));
  }

  @Test
  public void testExpression_CheckExternalField() {
    final int value = 1234;
    final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap(new JBBPExternalValueProvider() {

      @Override
      public int provideArraySize(final String fieldName, final JBBPNamedNumericFieldMap numericFieldMap, final JBBPCompiledBlock compiledBlock) {
        if (fieldName.equals("value")) {
          return value;
        }
        assertNotNull(numericFieldMap);
        assertNotNull(compiledBlock);
        fail("Unexpected request for value [" + fieldName + ']');
        return -1;
      }
    });

    final List<JBBPNamedFieldInfo> list = new ArrayList<JBBPNamedFieldInfo>();

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPExpressionEvaluator expr = new JBBPExpressionEvaluator("123*($value-45/3)", list, compiled);
    assertEquals(4, expr.getMaxStackDepth());
    assertEquals(123 * (value - 45 / 3), expr.eval(null, 0, compiledBlock, map));
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_CheckExternalField.map.new JBBPNamedNumericFieldMap.new JBBPExternalValueProvider with (fieldName, numericFieldMap, compiledBlock) -> {if(fieldName.equals("value")){return value; in method public testExpression_CheckExternalField() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testExpression_CheckExternalFieldAndStreamOffset() throws Exception {
    final int value = 1234;
    final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap((fieldName, numericFieldMap, compiledBlock) -> {
      if (fieldName.equals("value")) {
        return value;
      }
      assertNotNull(numericFieldMap);
      assertNotNull(compiledBlock);
      fail("Unexpected request for value [" + fieldName + ']');
      return -1;
    });

    final List<JBBPNamedFieldInfo> list = new ArrayList<>();

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPExpressionEvaluator expr = new JBBPExpressionEvaluator("123*($value-45/3)*$$", list, compiled);
    assertEquals(4, expr.getMaxStackDepth());

    final JBBPBitInputStream inStream = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5}));
    inStream.read();
    inStream.read();
    inStream.read();

    assertEquals(123 * (value - 45 / 3) * 3, expr.eval(inStream, 0, compiledBlock, map));
  }

  @Test
  public void testExpression_CheckExternalFieldAndStreamOffset() throws Exception {
    final int value = 1234;
    final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap(new JBBPExternalValueProvider() {

      @Override
      public int provideArraySize(final String fieldName, final JBBPNamedNumericFieldMap numericFieldMap, final JBBPCompiledBlock compiledBlock) {
        if (fieldName.equals("value")) {
          return value;
        }
        assertNotNull(numericFieldMap);
        assertNotNull(compiledBlock);
        fail("Unexpected request for value [" + fieldName + ']');
        return -1;
      }
    });

    final List<JBBPNamedFieldInfo> list = new ArrayList<JBBPNamedFieldInfo>();

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPExpressionEvaluator expr = new JBBPExpressionEvaluator("123*($value-45/3)*$$", list, compiled);
    assertEquals(4, expr.getMaxStackDepth());

    final JBBPBitInputStream inStream = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5}));
    inStream.read();
    inStream.read();
    inStream.read();

    assertEquals(123 * (value - 45 / 3) * 3, expr.eval(inStream, 0, compiledBlock, map));
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest.testExpression_CheckExternalFieldAndStreamOffset.map.new JBBPNamedNumericFieldMap.new JBBPExternalValueProvider with (fieldName, numericFieldMap, compiledBlock) -> {if(fieldName.equals("value")){return value; in method public testExpression_CheckExternalFieldAndStreamOffset() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPExpressionEvaluatorTest


  @Test
  public void testNumericValue() {
    final int value = 1234;
    final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap();
    final JBBPNamedFieldInfo nameInfo = new JBBPNamedFieldInfo("value", "value", value);

    map.putField(new JBBPFieldInt(nameInfo, value));

    final List<JBBPNamedFieldInfo> list = new ArrayList<>();
    list.add(nameInfo);

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPOnlyFieldEvaluator expr = new JBBPOnlyFieldEvaluator(null, 0);
    assertEquals(value, expr.eval(null, 0, compiledBlock, map));
  }

  @Test
  public void testNumericValue() {
    final int value = 1234;
    final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap();
    final JBBPNamedFieldInfo nameInfo = new JBBPNamedFieldInfo("value", "value", value);

    map.putField(new JBBPFieldInt(nameInfo, value));

    final List<JBBPNamedFieldInfo> list = new ArrayList<JBBPNamedFieldInfo>();
    list.add(nameInfo);

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPOnlyFieldEvaluator expr = new JBBPOnlyFieldEvaluator(null, 0);
    assertEquals(value, expr.eval(null, 0, compiledBlock, map));
  }

Replace Generic With Diamond ArrayList<JBBPNamedFieldInfo> with ArrayList<> in method public testNumericValue() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPOnlyFieldEvaluatorTest


  @Test
  public void testExternalValue() {
    final int value = 1234;
    final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap((fieldName, numericFieldMap, compiledBlock) -> {
      if (fieldName.equals("value")) {
        return value;
      }
      assertNotNull(numericFieldMap);
      assertNotNull(compiledBlock);
      fail("Unexpected request for value [" + fieldName + ']');
      return -1;
    });

    final List<JBBPNamedFieldInfo> list = new ArrayList<>();

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPOnlyFieldEvaluator expr = new JBBPOnlyFieldEvaluator("value", -1);
    assertEquals(value, expr.eval(null, 0, compiledBlock, map));
  }

  @Test
  public void testExternalValue() {
    final int value = 1234;
    final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap(new JBBPExternalValueProvider() {

      @Override
      public int provideArraySize(final String fieldName, final JBBPNamedNumericFieldMap numericFieldMap, final JBBPCompiledBlock compiledBlock) {
        if (fieldName.equals("value")) {
          return value;
        }
        assertNotNull(numericFieldMap);
        assertNotNull(compiledBlock);
        fail("Unexpected request for value [" + fieldName + ']');
        return -1;
      }
    });

    final List<JBBPNamedFieldInfo> list = new ArrayList<JBBPNamedFieldInfo>();

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPOnlyFieldEvaluator expr = new JBBPOnlyFieldEvaluator("value", -1);
    assertEquals(value, expr.eval(null, 0, compiledBlock, map));
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPOnlyFieldEvaluatorTest.testExternalValue.map.new JBBPNamedNumericFieldMap.new JBBPExternalValueProvider with (fieldName, numericFieldMap, compiledBlock) -> {if(fieldName.equals("value")){return value; in method public testExternalValue() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPOnlyFieldEvaluatorTest


  @Test
  public void testExternalValueNamedAsFirstCharDollar() {
    final int value = 1234;
    final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap((fieldName, numericFieldMap, compiledBlock) -> {
      if (fieldName.equals("$value")) {
        return value;
      }
      assertNotNull(numericFieldMap);
      assertNotNull(compiledBlock);
      fail("Unexpected request for value [" + fieldName + ']');
      return -1;
    });

    final List<JBBPNamedFieldInfo> list = new ArrayList<>();

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPOnlyFieldEvaluator expr = new JBBPOnlyFieldEvaluator("$value", -1);
    assertEquals(value, expr.eval(null, 0, compiledBlock, map));
  }

  @Test
  public void testExternalValueNamedAsFirstCharDollar() {
    final int value = 1234;
    final JBBPNamedNumericFieldMap map = new JBBPNamedNumericFieldMap(new JBBPExternalValueProvider() {

      @Override
      public int provideArraySize(final String fieldName, final JBBPNamedNumericFieldMap numericFieldMap, final JBBPCompiledBlock compiledBlock) {
        if (fieldName.equals("$value")) {
          return value;
        }
        assertNotNull(numericFieldMap);
        assertNotNull(compiledBlock);
        fail("Unexpected request for value [" + fieldName + ']');
        return -1;
      }
    });

    final List<JBBPNamedFieldInfo> list = new ArrayList<JBBPNamedFieldInfo>();

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPOnlyFieldEvaluator expr = new JBBPOnlyFieldEvaluator("$value", -1);
    assertEquals(value, expr.eval(null, 0, compiledBlock, map));
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.compiler.varlen.JBBPOnlyFieldEvaluatorTest.testExternalValueNamedAsFirstCharDollar.map.new JBBPNamedNumericFieldMap.new JBBPExternalValueProvider with (fieldName, numericFieldMap, compiledBlock) -> {if(fieldName.equals("$value")){return value; in method public testExternalValueNamedAsFirstCharDollar() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPOnlyFieldEvaluatorTest


  @Test
  public void testCounterOfStreamAsParameter() throws Exception {
    final List<JBBPNamedFieldInfo> list = new ArrayList<>();

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPOnlyFieldEvaluator expr = new JBBPOnlyFieldEvaluator("$", -1);

    final JBBPBitInputStream inStream = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5}));
    inStream.read();
    inStream.read();
    inStream.read();

    assertEquals(3, expr.eval(inStream, 0, compiledBlock, null));
  }

  @Test
  public void testCounterOfStreamAsParameter() throws Exception {
    final List<JBBPNamedFieldInfo> list = new ArrayList<JBBPNamedFieldInfo>();

    final byte[] compiled = new byte[] {0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPOnlyFieldEvaluator expr = new JBBPOnlyFieldEvaluator("$", -1);

    final JBBPBitInputStream inStream = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5}));
    inStream.read();
    inStream.read();
    inStream.read();

    assertEquals(3, expr.eval(inStream, 0, compiledBlock, null));
  }

Replace Generic With Diamond ArrayList<JBBPNamedFieldInfo> with ArrayList<> in method public testCounterOfStreamAsParameter() : void from class com.igormaznitsa.jbbp.compiler.varlen.JBBPOnlyFieldEvaluatorTest


  @Test
  public void testReadUnsignedShort_EOFforEmpty_BigEndian_EOFException() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream().readUnsignedShort(JBBPByteOrder.BIG_ENDIAN));
  }

  @Test
  public void testReadUnsignedShort_EOFforEmpty_BigEndian_EOFException() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream().readUnsignedShort(JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadUnsignedShort_EOFforEmpty_BigEndian_EOFException.assertThrows.new Executable with () -> asInputStream().readUnsignedShort(JBBPByteOrder.BIG_ENDIAN) in method public testReadUnsignedShort_EOFforEmpty_BigEndian_EOFException() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadUnsignedShort_EOFforEmpty_LittleEndian_EOFException() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream().readUnsignedShort(JBBPByteOrder.LITTLE_ENDIAN));
  }

  @Test
  public void testReadUnsignedShort_EOFforEmpty_LittleEndian_EOFException() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream().readUnsignedShort(JBBPByteOrder.LITTLE_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadUnsignedShort_EOFforEmpty_LittleEndian_EOFException.assertThrows.new Executable with () -> asInputStream().readUnsignedShort(JBBPByteOrder.LITTLE_ENDIAN) in method public testReadUnsignedShort_EOFforEmpty_LittleEndian_EOFException() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadUnsignedShort_EOFforOneByte_BigEndian_EOFException() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream((byte) 1).readUnsignedShort(JBBPByteOrder.BIG_ENDIAN));
  }

  @Test
  public void testReadUnsignedShort_EOFforOneByte_BigEndian_EOFException() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream((byte) 1).readUnsignedShort(JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadUnsignedShort_EOFforOneByte_BigEndian_EOFException.assertThrows.new Executable with () -> asInputStream((byte)1).readUnsignedShort(JBBPByteOrder.BIG_ENDIAN) in method public testReadUnsignedShort_EOFforOneByte_BigEndian_EOFException() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadUnsignedShort_EOFforOneByte_LittleEndian_EOFException() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream((byte) 1).readUnsignedShort(JBBPByteOrder.LITTLE_ENDIAN));
  }

  @Test
  public void testReadUnsignedShort_EOFforOneByte_LittleEndian_EOFException() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream((byte) 1).readUnsignedShort(JBBPByteOrder.LITTLE_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadUnsignedShort_EOFforOneByte_LittleEndian_EOFException.assertThrows.new Executable with () -> asInputStream((byte)1).readUnsignedShort(JBBPByteOrder.LITTLE_ENDIAN) in method public testReadUnsignedShort_EOFforOneByte_LittleEndian_EOFException() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadInt_BigEndian_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream(0x12, 0x34, 0x56).readInt(JBBPByteOrder.BIG_ENDIAN));
  }

  @Test
  public void testReadInt_BigEndian_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream(0x12, 0x34, 0x56).readInt(JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadInt_BigEndian_EOF.assertThrows.new Executable with () -> asInputStream(0x12,0x34,0x56).readInt(JBBPByteOrder.BIG_ENDIAN) in method public testReadInt_BigEndian_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadInt_BigEndian_MSB0_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStreamMSB0(0x12, 0x34, 0x56).readInt(JBBPByteOrder.BIG_ENDIAN));
  }

  @Test
  public void testReadInt_BigEndian_MSB0_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStreamMSB0(0x12, 0x34, 0x56).readInt(JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadInt_BigEndian_MSB0_EOF.assertThrows.new Executable with () -> asInputStreamMSB0(0x12,0x34,0x56).readInt(JBBPByteOrder.BIG_ENDIAN) in method public testReadInt_BigEndian_MSB0_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadFloat_BigEndian_MSB0_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStreamMSB0(0x12, 0x34, 0x56).readFloat(JBBPByteOrder.BIG_ENDIAN));
  }

  @Test
  public void testReadFloat_BigEndian_MSB0_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStreamMSB0(0x12, 0x34, 0x56).readFloat(JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadFloat_BigEndian_MSB0_EOF.assertThrows.new Executable with () -> asInputStreamMSB0(0x12,0x34,0x56).readFloat(JBBPByteOrder.BIG_ENDIAN) in method public testReadFloat_BigEndian_MSB0_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadInt_LittleEndian_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream(0x12, 0x34, 0x56).readInt(JBBPByteOrder.LITTLE_ENDIAN));
  }

  @Test
  public void testReadInt_LittleEndian_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream(0x12, 0x34, 0x56).readInt(JBBPByteOrder.LITTLE_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadInt_LittleEndian_EOF.assertThrows.new Executable with () -> asInputStream(0x12,0x34,0x56).readInt(JBBPByteOrder.LITTLE_ENDIAN) in method public testReadInt_LittleEndian_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadFloat_LittleEndian_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream(0x12, 0x34, 0x56).readFloat(JBBPByteOrder.LITTLE_ENDIAN));
  }

  @Test
  public void testReadFloat_LittleEndian_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream(0x12, 0x34, 0x56).readFloat(JBBPByteOrder.LITTLE_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadFloat_LittleEndian_EOF.assertThrows.new Executable with () -> asInputStream(0x12,0x34,0x56).readFloat(JBBPByteOrder.LITTLE_ENDIAN) in method public testReadFloat_LittleEndian_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadInt_LittleEndian_MSB0_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStreamMSB0(0x12, 0x34, 0x56).readInt(JBBPByteOrder.LITTLE_ENDIAN));
  }

  @Test
  public void testReadInt_LittleEndian_MSB0_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStreamMSB0(0x12, 0x34, 0x56).readInt(JBBPByteOrder.LITTLE_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadInt_LittleEndian_MSB0_EOF.assertThrows.new Executable with () -> asInputStreamMSB0(0x12,0x34,0x56).readInt(JBBPByteOrder.LITTLE_ENDIAN) in method public testReadInt_LittleEndian_MSB0_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadFloat_LittleEndian_MSB0_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStreamMSB0(0x12, 0x34, 0x56).readFloat(JBBPByteOrder.LITTLE_ENDIAN));
  }

  @Test
  public void testReadFloat_LittleEndian_MSB0_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStreamMSB0(0x12, 0x34, 0x56).readFloat(JBBPByteOrder.LITTLE_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadFloat_LittleEndian_MSB0_EOF.assertThrows.new Executable with () -> asInputStreamMSB0(0x12,0x34,0x56).readFloat(JBBPByteOrder.LITTLE_ENDIAN) in method public testReadFloat_LittleEndian_MSB0_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadLong_BigEndian_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream(0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC).readLong(JBBPByteOrder.BIG_ENDIAN));
  }

  @Test
  public void testReadLong_BigEndian_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream(0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC).readLong(JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadLong_BigEndian_EOF.assertThrows.new Executable with () -> asInputStream(0x12,0x34,0x56,0x78,0xAA,0xBB,0xCC).readLong(JBBPByteOrder.BIG_ENDIAN) in method public testReadLong_BigEndian_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadDouble_BigEndian_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream(0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC).readDouble(JBBPByteOrder.BIG_ENDIAN));
  }

  @Test
  public void testReadDouble_BigEndian_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream(0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC).readDouble(JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadDouble_BigEndian_EOF.assertThrows.new Executable with () -> asInputStream(0x12,0x34,0x56,0x78,0xAA,0xBB,0xCC).readDouble(JBBPByteOrder.BIG_ENDIAN) in method public testReadDouble_BigEndian_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadLong_LittleEndian_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream(0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC).readLong(JBBPByteOrder.LITTLE_ENDIAN));
  }

  @Test
  public void testReadLong_LittleEndian_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream(0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC).readLong(JBBPByteOrder.LITTLE_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadLong_LittleEndian_EOF.assertThrows.new Executable with () -> asInputStream(0x12,0x34,0x56,0x78,0xAA,0xBB,0xCC).readLong(JBBPByteOrder.LITTLE_ENDIAN) in method public testReadLong_LittleEndian_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadDouble_LittleEndian_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream(0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC).readDouble(JBBPByteOrder.LITTLE_ENDIAN));
  }

  @Test
  public void testReadDouble_LittleEndian_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream(0x12, 0x34, 0x56, 0x78, 0xAA, 0xBB, 0xCC).readDouble(JBBPByteOrder.LITTLE_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadDouble_LittleEndian_EOF.assertThrows.new Executable with () -> asInputStream(0x12,0x34,0x56,0x78,0xAA,0xBB,0xCC).readDouble(JBBPByteOrder.LITTLE_ENDIAN) in method public testReadDouble_LittleEndian_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadArray_Bits_EOF() throws Exception {
    assertThrows(EOFException.class, () -> {
      final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(JBBPUtils.str2bin("00101001_11001011_10111110", JBBPBitOrder.LSB0)));
      in.readBitsArray(58, JBBPBitNumber.BITS_2);
    });
  }

  @Test
  public void testReadArray_Bits_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(JBBPUtils.str2bin("00101001_11001011_10111110", JBBPBitOrder.LSB0)));
        in.readBitsArray(58, JBBPBitNumber.BITS_2);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadArray_Bits_EOF.assertThrows.new Executable with () -> {final JBBPBitInputStream in=new JBBPBitInputStream(new ByteArrayInputStream(JBBPUtils.str2bin("00101001_11001011_10111110",JBBPBitOrder.LSB0))); in method public testReadArray_Bits_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadArray_Bytes_EOF() throws Exception {
    assertThrows(EOFException.class, () -> {
      final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0}));
      in.readByteArray(259);
    });
  }

  @Test
  public void testReadArray_Bytes_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0}));
        in.readByteArray(259);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadArray_Bytes_EOF.assertThrows.new Executable with () -> {final JBBPBitInputStream in=new JBBPBitInputStream(new ByteArrayInputStream(new byte[]{1,2,3,4,5,6,7,0})); in method public testReadArray_Bytes_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadArray_Short_EOF() throws Exception {
    assertThrows(EOFException.class, () -> {
      final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0}));
      in.readShortArray(259, JBBPByteOrder.BIG_ENDIAN);
    });
  }

  @Test
  public void testReadArray_Short_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0}));
        in.readShortArray(259, JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadArray_Short_EOF.assertThrows.new Executable with () -> {final JBBPBitInputStream in=new JBBPBitInputStream(new ByteArrayInputStream(new byte[]{1,2,3,4,5,6,7,0})); in method public testReadArray_Short_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadArray_Int_EOF() throws Exception {
    assertThrows(EOFException.class, () -> {
      final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0, (byte) 0xFE, (byte) 0xCA, (byte) 0xBE, (byte) 0x01}));
      in.readIntArray(259, JBBPByteOrder.BIG_ENDIAN);
    });
  }

  @Test
  public void testReadArray_Int_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0, (byte) 0xFE, (byte) 0xCA, (byte) 0xBE, (byte) 0x01}));
        in.readIntArray(259, JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadArray_Int_EOF.assertThrows.new Executable with () -> {final JBBPBitInputStream in=new JBBPBitInputStream(new ByteArrayInputStream(new byte[]{1,2,3,4,5,6,7,0,(byte)0xFE,(byte)0xCA,(byte)0xBE,(byte)0x01})); in method public testReadArray_Int_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadArray_DoubleInt_EOF() throws Exception {
    assertThrows(EOFException.class, () -> {
      final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0, (byte) 0xFE, (byte) 0xCA, (byte) 0xBE, (byte) 0x01}));
      in.readFloatArray(259, JBBPByteOrder.BIG_ENDIAN);
    });
  }

  @Test
  public void testReadArray_DoubleInt_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0, (byte) 0xFE, (byte) 0xCA, (byte) 0xBE, (byte) 0x01}));
        in.readFloatArray(259, JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadArray_DoubleInt_EOF.assertThrows.new Executable with () -> {final JBBPBitInputStream in=new JBBPBitInputStream(new ByteArrayInputStream(new byte[]{1,2,3,4,5,6,7,0,(byte)0xFE,(byte)0xCA,(byte)0xBE,(byte)0x01})); in method public testReadArray_DoubleInt_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadArray_Long_EOF() throws Exception {
    assertThrows(EOFException.class, () -> {
      final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0, (byte) 0xFE, (byte) 0xCA, (byte) 0xBE, (byte) 0x01, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4}));
      in.readLongArray(259, JBBPByteOrder.BIG_ENDIAN);
    });
  }

  @Test
  public void testReadArray_Long_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0, (byte) 0xFE, (byte) 0xCA, (byte) 0xBE, (byte) 0x01, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4}));
        in.readLongArray(259, JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadArray_Long_EOF.assertThrows.new Executable with () -> {final JBBPBitInputStream in=new JBBPBitInputStream(new ByteArrayInputStream(new byte[]{1,2,3,4,5,6,7,0,(byte)0xFE,(byte)0xCA,(byte)0xBE,(byte)0x01,2,3,4,5,6,7,8,9,1,2,3,4})); in method public testReadArray_Long_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadArray_Double_EOF() throws Exception {
    assertThrows(EOFException.class, () -> {
      final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0, (byte) 0xFE, (byte) 0xCA, (byte) 0xBE, (byte) 0x01, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4}));
      in.readDoubleArray(259, JBBPByteOrder.BIG_ENDIAN);
    });
  }

  @Test
  public void testReadArray_Double_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        final JBBPBitInputStream in = new JBBPBitInputStream(new ByteArrayInputStream(new byte[] {1, 2, 3, 4, 5, 6, 7, 0, (byte) 0xFE, (byte) 0xCA, (byte) 0xBE, (byte) 0x01, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4}));
        in.readDoubleArray(259, JBBPByteOrder.BIG_ENDIAN);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadArray_Double_EOF.assertThrows.new Executable with () -> {final JBBPBitInputStream in=new JBBPBitInputStream(new ByteArrayInputStream(new byte[]{1,2,3,4,5,6,7,0,(byte)0xFE,(byte)0xCA,(byte)0xBE,(byte)0x01,2,3,4,5,6,7,8,9,1,2,3,4})); in method public testReadArray_Double_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testReadBooleanArray_EOF() throws Exception {
    assertThrows(EOFException.class, () -> asInputStream(1, 2, 3, 4, 5, 6).readBoolArray(256));
  }

  @Test
  public void testReadBooleanArray_EOF() throws Exception {
    assertThrows(EOFException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        asInputStream(1, 2, 3, 4, 5, 6).readBoolArray(256);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest.testReadBooleanArray_EOF.assertThrows.new Executable with () -> asInputStream(1,2,3,4,5,6).readBoolArray(256) in method public testReadBooleanArray_EOF() : void from class com.igormaznitsa.jbbp.io.JBBPBitInputStreamTest


  @Test
  public void testWriteBit_ErrorForZeroSize() throws Exception {
    assertThrows(IllegalArgumentException.class, () -> new JBBPBitOutputStream(new ByteArrayOutputStream()).writeBits(4, JBBPBitNumber.decode(0)));
  }

  @Test
  public void testWriteBit_ErrorForZeroSize() throws Exception {
    assertThrows(IllegalArgumentException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPBitOutputStream(new ByteArrayOutputStream()).writeBits(4, JBBPBitNumber.decode(0));
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitOutputStreamTest.testWriteBit_ErrorForZeroSize.assertThrows.new Executable with () -> new JBBPBitOutputStream(new ByteArrayOutputStream()).writeBits(4,JBBPBitNumber.decode(0)) in method public testWriteBit_ErrorForZeroSize() : void from class com.igormaznitsa.jbbp.io.JBBPBitOutputStreamTest


  @Test
  public void testWriteBit_ErrorForNegativeSize() throws Exception {
    assertThrows(IllegalArgumentException.class, () -> new JBBPBitOutputStream(new ByteArrayOutputStream()).writeBits(4, JBBPBitNumber.decode(-1)));
  }

  @Test
  public void testWriteBit_ErrorForNegativeSize() throws Exception {
    assertThrows(IllegalArgumentException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPBitOutputStream(new ByteArrayOutputStream()).writeBits(4, JBBPBitNumber.decode(-1));
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitOutputStreamTest.testWriteBit_ErrorForNegativeSize.assertThrows.new Executable with () -> new JBBPBitOutputStream(new ByteArrayOutputStream()).writeBits(4,JBBPBitNumber.decode(-1)) in method public testWriteBit_ErrorForNegativeSize() : void from class com.igormaznitsa.jbbp.io.JBBPBitOutputStreamTest


  @Test
  public void testWriteBit_ErrorForTooBigSize() throws Exception {
    assertThrows(IllegalArgumentException.class, () -> new JBBPBitOutputStream(new ByteArrayOutputStream()).writeBits(4, JBBPBitNumber.decode(9)));
  }

  @Test
  public void testWriteBit_ErrorForTooBigSize() throws Exception {
    assertThrows(IllegalArgumentException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        new JBBPBitOutputStream(new ByteArrayOutputStream()).writeBits(4, JBBPBitNumber.decode(9));
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPBitOutputStreamTest.testWriteBit_ErrorForTooBigSize.assertThrows.new Executable with () -> new JBBPBitOutputStream(new ByteArrayOutputStream()).writeBits(4,JBBPBitNumber.decode(9)) in method public testWriteBit_ErrorForTooBigSize() : void from class com.igormaznitsa.jbbp.io.JBBPBitOutputStreamTest


  @Test
  public void testSkip_ErrorForNegativeValue() throws Exception {
    assertThrows(IllegalArgumentException.class, () -> BeginBin().Skip(-1));
  }

  @Test
  public void testSkip_ErrorForNegativeValue() throws Exception {
    assertThrows(IllegalArgumentException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        BeginBin().Skip(-1);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPOutTest.testSkip_ErrorForNegativeValue.assertThrows.new Executable with () -> BeginBin().Skip(-1) in method public testSkip_ErrorForNegativeValue() : void from class com.igormaznitsa.jbbp.io.JBBPOutTest


  @Test
  public void testShort_String_NPEForNullString() throws Exception {
    assertThrows(NullPointerException.class, () -> BeginBin().Short((String) null).End());
  }

  @Test
  public void testShort_String_NPEForNullString() throws Exception {
    assertThrows(NullPointerException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        BeginBin().Short((String) null).End();
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPOutTest.testShort_String_NPEForNullString.assertThrows.new Executable with () -> BeginBin().Short((String)null).End() in method public testShort_String_NPEForNullString() : void from class com.igormaznitsa.jbbp.io.JBBPOutTest


  @Test
  public void testExceptionForBitOrderConfilctInCaseOfUsageBitOutputStream() throws Exception {
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    final JBBPBitOutputStream bitstream = new JBBPBitOutputStream(buffer, JBBPBitOrder.LSB0);

    assertThrows(IllegalArgumentException.class, () -> BeginBin(bitstream, JBBPByteOrder.BIG_ENDIAN, JBBPBitOrder.MSB0));
  }

  @Test
  public void testExceptionForBitOrderConfilctInCaseOfUsageBitOutputStream() throws Exception {
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    final JBBPBitOutputStream bitstream = new JBBPBitOutputStream(buffer, JBBPBitOrder.LSB0);

    assertThrows(IllegalArgumentException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        BeginBin(bitstream, JBBPByteOrder.BIG_ENDIAN, JBBPBitOrder.MSB0);
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPOutTest.testExceptionForBitOrderConfilctInCaseOfUsageBitOutputStream.assertThrows.new Executable with () -> BeginBin(bitstream,JBBPByteOrder.BIG_ENDIAN,JBBPBitOrder.MSB0) in method public testExceptionForBitOrderConfilctInCaseOfUsageBitOutputStream() : void from class com.igormaznitsa.jbbp.io.JBBPOutTest


  @Test
  public void testVar_NPEForNullProcessor() throws Exception {
    assertThrows(NullPointerException.class, () -> BeginBin().Var(null).End());
  }

  @Test
  public void testVar_NPEForNullProcessor() throws Exception {
    assertThrows(NullPointerException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        BeginBin().Var(null).End();
      }
    });
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPOutTest.testVar_NPEForNullProcessor.assertThrows.new Executable with () -> BeginBin().Var(null).End() in method public testVar_NPEForNullProcessor() : void from class com.igormaznitsa.jbbp.io.JBBPOutTest


  @Test
  public void testVar_ProcessRest() throws Exception {
    class Test {

      @Bin(outOrder = 1)
      byte a;
      @Bin(outOrder = 2)
      byte b;

      Test(int a, int b) {
        this.a = (byte) a;
        this.b = (byte) b;
      }
    }

    final byte[] array = BeginBin().
        Byte(0xCC).
        Var((context, outStream, args) -> {
          assertNotNull(context);
          assertNotNull(outStream);
          assertEquals(0, args.length);
          outStream.write(0xDD);
          return true;
        }).
        Byte(0xAA).
        Bin(new Test(0x12, 0x13)).
        End().toByteArray();

    assertArrayEquals(new byte[] {(byte) 0xCC, (byte) 0xDD, (byte) 0xAA, (byte) 0x12, (byte) 0x13}, array);
  }

  @Test
  public void testVar_ProcessRest() throws Exception {
    class Test {

      @Bin(outOrder = 1)
      byte a;
      @Bin(outOrder = 2)
      byte b;

      Test(int a, int b) {
        this.a = (byte) a;
        this.b = (byte) b;
      }
    }

    final byte[] array = BeginBin().
        Byte(0xCC).
        Var(new JBBPOutVarProcessor() {

          @Override
          public boolean processVarOut(final JBBPOut context, final JBBPBitOutputStream outStream, final Object... args) throws IOException {
            assertNotNull(context);
            assertNotNull(outStream);
            assertEquals(0, args.length);
            outStream.write(0xDD);
            return true;
          }
        }).
        Byte(0xAA).
        Bin(new Test(0x12, 0x13)).
        End().toByteArray();

    assertArrayEquals(new byte[] {(byte) 0xCC, (byte) 0xDD, (byte) 0xAA, (byte) 0x12, (byte) 0x13}, array);
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPOutTest.testVar_ProcessRest.array.toByteArray.End.Bin.Byte.Var.new JBBPOutVarProcessor with (context, outStream, args) -> {assertNotNull(context); in method public testVar_ProcessRest() : void from class com.igormaznitsa.jbbp.io.JBBPOutTest


  @Test
  public void testVar_SkipRest() throws Exception {
    class Test {

      @Bin(outOrder = 1)
      byte a;
      @Bin(outOrder = 2)
      byte b;

      Test(int a, int b) {
        this.a = (byte) a;
        this.b = (byte) b;
      }
    }

    final byte[] array = BeginBin().
        Byte(0xCC).
        Var((context, outStream, args) -> {
          assertNotNull(context);
          assertNotNull(outStream);
          assertEquals(0, args.length);
          outStream.write(0xDD);
          return false;
        }).
        Byte(0xAA).
        Align(15).
        Align().
        Bit(true).
        Bit(34).
        Bit(true, false).
        Bit((byte) 11).
        Bit(new byte[] {(byte) 11, (byte) 45}).
        Bit(111, 222).
        Bits(JBBPBitNumber.BITS_5, 0xFF).
        Bits(JBBPBitNumber.BITS_5, 0xFF, 0xAB).
        Bits(JBBPBitNumber.BITS_5, new byte[] {(byte) 0xFF, (byte) 0xAB}).
        Bool(true).
        Bool(false, false).
        Byte("HURRAAA").
        Byte(new byte[] {(byte) 1, (byte) 2, (byte) 3}).
        Byte(232324).
        Byte(2322342, 2323232).
        ByteOrder(JBBPByteOrder.LITTLE_ENDIAN).
        Int(23432432).
        Int(234234234, 234234234).
        Long(234823948234L).
        Long(234823948234L, 234233243243L).
        Short(234).
        Short(234, 233).
        Short(new short[] {(short) 234, (short) 233}).
        Skip(332).
        Bin(new Test(12, 34)).
        Utf8("werwerew").
        Var((context, outStream, args) -> {
          fail("Must not be called");
          return false;
        }).
        End().toByteArray();

    assertArrayEquals(new byte[] {(byte) 0xCC, (byte) 0xDD}, array);
  }

  @Test
  public void testVar_SkipRest() throws Exception {
    class Test {

      @Bin(outOrder = 1)
      byte a;
      @Bin(outOrder = 2)
      byte b;

      Test(int a, int b) {
        this.a = (byte) a;
        this.b = (byte) b;
      }
    }

    final byte[] array = BeginBin().
        Byte(0xCC).
        Var(new JBBPOutVarProcessor() {

          @Override
          public boolean processVarOut(final JBBPOut context, final JBBPBitOutputStream outStream, final Object... args) throws IOException {
            assertNotNull(context);
            assertNotNull(outStream);
            assertEquals(0, args.length);
            outStream.write(0xDD);
            return false;
          }
        }).
        Byte(0xAA).
        Align(15).
        Align().
        Bit(true).
        Bit(34).
        Bit(true, false).
        Bit((byte) 11).
        Bit(new byte[] {(byte) 11, (byte) 45}).
        Bit(111, 222).
        Bits(JBBPBitNumber.BITS_5, 0xFF).
        Bits(JBBPBitNumber.BITS_5, 0xFF, 0xAB).
        Bits(JBBPBitNumber.BITS_5, new byte[] {(byte) 0xFF, (byte) 0xAB}).
        Bool(true).
        Bool(false, false).
        Byte("HURRAAA").
        Byte(new byte[] {(byte) 1, (byte) 2, (byte) 3}).
        Byte(232324).
        Byte(2322342, 2323232).
        ByteOrder(JBBPByteOrder.LITTLE_ENDIAN).
        Int(23432432).
        Int(234234234, 234234234).
        Long(234823948234L).
        Long(234823948234L, 234233243243L).
        Short(234).
        Short(234, 233).
        Short(new short[] {(short) 234, (short) 233}).
        Skip(332).
        Bin(new Test(12, 34)).
        Utf8("werwerew").
        Var(new JBBPOutVarProcessor() {

          @Override
          public boolean processVarOut(JBBPOut context, JBBPBitOutputStream outStream, Object... args) throws IOException {
            fail("Must not be called");
            return false;
          }
        }).
        End().toByteArray();

    assertArrayEquals(new byte[] {(byte) 0xCC, (byte) 0xDD}, array);
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPOutTest.testVar_SkipRest.array.toByteArray.End.Var.Utf8.Bin.Skip.Short.Short.Short.Long.Long.Int.Int.ByteOrder.Byte.Byte.Byte.Byte.Bool.Bool.Bits.Bits.Bits.Bit.Bit.Bit.Bit.Bit.Bit.Align.Align.Byte.Var.new JBBPOutVarProcessor with (context, outStream, args) -> {assertNotNull(context); in method public testVar_SkipRest() : void from class com.igormaznitsa.jbbp.io.JBBPOutTest


  @Test
  public void testVar_VariableContent() throws Exception {
    final JBBPOutVarProcessor var = (context, outStream, args) -> {
      final int type = (Integer) args[0];
      switch (type) {
        case 0: {
          context.Int(0x01020304);
        }
        break;
        case 1: {
          context.Int(0x05060708);
        }
        break;
        default: {
          fail("Unexpected parameter [" + type + ']');
        }
        break;
      }
      return true;
    };

    final byte[] array = BeginBin().
        Var(var, 0).
        Var(var, 1).
        End().toByteArray();

    assertArrayEquals(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}, array);
  }

  @Test
  public void testVar_VariableContent() throws Exception {
    final JBBPOutVarProcessor var = new JBBPOutVarProcessor() {
      @Override
      public boolean processVarOut(JBBPOut context, JBBPBitOutputStream outStream, Object... args) throws IOException {
        final int type = (Integer) args[0];
        switch (type) {
          case 0: {
            context.Int(0x01020304);
          }
          break;
          case 1: {
            context.Int(0x05060708);
          }
          break;
          default: {
            fail("Unexpected parameter [" + type + ']');
          }
          break;
        }
        return true;
      }
    };

    final byte[] array = BeginBin().
        Var(var, 0).
        Var(var, 1).
        End().toByteArray();

    assertArrayEquals(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}, array);
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPOutTest.testVar_VariableContent.var.new JBBPOutVarProcessor with (context, outStream, args) -> {final int type=(Integer)args[0]; in method public testVar_VariableContent() : void from class com.igormaznitsa.jbbp.io.JBBPOutTest


  @Test
  public void testBin_CustomField_ErrorBecauseNoCustomWriter() throws Exception {
    class Test {

      @Bin(outOrder = 1)
      byte a;
      @Bin(outOrder = 2, custom = true)
      byte b;

      Test(byte a, byte b) {
        this.a = a;
        this.b = b;
      }
    }

    assertThrows(JBBPIllegalArgumentException.class, () -> BeginBin().Bin(new Test((byte) 12, (byte) 24)));

  }

  @Test
  public void testBin_CustomField_ErrorBecauseNoCustomWriter() throws Exception {
    class Test {

      @Bin(outOrder = 1)
      byte a;
      @Bin(outOrder = 2, custom = true)
      byte b;

      Test(byte a, byte b) {
        this.a = a;
        this.b = b;
      }
    }

    assertThrows(JBBPIllegalArgumentException.class, new Executable() {
      @Override
      public void execute() throws Throwable {
        BeginBin().Bin(new Test((byte) 12, (byte) 24));
      }
    });

  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPOutTest.testBin_CustomField_ErrorBecauseNoCustomWriter.assertThrows.new Executable with () -> BeginBin().Bin(new Test((byte)12,(byte)24)) in method public testBin_CustomField_ErrorBecauseNoCustomWriter() : void from class com.igormaznitsa.jbbp.io.JBBPOutTest


  @Test
  public void testBin_CustomField_NoError() throws Exception {
    class Test {
      @Bin(outOrder = 1)
      byte a;
      @Bin(outOrder = 2, custom = true)
      byte b;

      Test(byte a, byte b) {
        this.a = a;
        this.b = b;
      }
    }

    assertArrayEquals(new byte[] {1, 2, 3}, BeginBin().Bin(new Test((byte) 1, (byte) 0), (context, outStream, instanceToSave, instanceCustomField, fieldAnnotation, value) -> {
      assertNotNull(context);
      assertNotNull(outStream);
      assertNotNull(instanceToSave);
      assertNotNull(instanceCustomField);
      assertNotNull(fieldAnnotation);
      assertEquals("b", instanceCustomField.getName());
      assertTrue(instanceToSave.getClass() == instanceCustomField.getDeclaringClass());

      context.Byte(2, 3);
    }).End().toByteArray());
  }

  @Test
  public void testBin_CustomField_NoError() throws Exception {
    class Test {
      @Bin(outOrder = 1)
      byte a;
      @Bin(outOrder = 2, custom = true)
      byte b;

      Test(byte a, byte b) {
        this.a = a;
        this.b = b;
      }
    }

    assertArrayEquals(new byte[] {1, 2, 3}, BeginBin().Bin(new Test((byte) 1, (byte) 0), new JBBPCustomFieldWriter() {
      @Override
      public void writeCustomField(JBBPOut context, JBBPBitOutputStream outStream, Object instanceToSave, Field instanceCustomField, Bin fieldAnnotation, Object value) throws IOException {
        assertNotNull(context);
        assertNotNull(outStream);
        assertNotNull(instanceToSave);
        assertNotNull(instanceCustomField);
        assertNotNull(fieldAnnotation);
        assertEquals("b", instanceCustomField.getName());
        assertTrue(instanceToSave.getClass() == instanceCustomField.getDeclaringClass());

        context.Byte(2, 3);
      }
    }).End().toByteArray());
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.io.JBBPOutTest.testBin_CustomField_NoError.assertArrayEquals.toByteArray.End.Bin.new JBBPCustomFieldWriter with (context, outStream, instanceToSave, instanceCustomField, fieldAnnotation, value) -> {assertNotNull(context); in method public testBin_CustomField_NoError() : void from class com.igormaznitsa.jbbp.io.JBBPOutTest


/**
   * Case 28-jul-2016
   * Simultaneous usage of expression evaluator from multiple threads.
   *
   * Issue #10, assertArrayLength throws exception in multi-thread
   *
   * @throws Exception for any error
   */
  @Test
  public void testMutlithredUsageOfParser() throws Exception {
    final JBBPParser parserIP = JBBPParser.prepare("skip:14; // skip bytes till the frame\n"
        + "bit:4 InternetHeaderLength;"
        + "bit:4 Version;"
        + "bit:2 ECN;"
        + "bit:6 DSCP;"
        + "ushort TotalPacketLength;"
        + "ushort Identification;"
        + "bit:8 IPFlagsAndFragmentOffset_low;"
        + "bit:5 IPFlagsAndFragmentOffset_high;"
        + "bit:1 MoreFragment;"
        + "bit:1 DonotFragment;"
        + "bit:1 ReservedBit;"
        + "ubyte TTL;"
        + "ubyte Protocol;"
        + "ushort HeaderChecksum;"
        + "int SourceAddress;"
        + "int DestinationAddress;"
        + "byte [(InternetHeaderLength-5)*4] Options;");

    final JBBPParser parserTCP = JBBPParser.prepare("skip:34; // skip bytes till the frame\n"
        + "ushort SourcePort;"
        + "ushort DestinationPort;"
        + "int SequenceNumber;"
        + "int AcknowledgementNumber;"
        + "bit:1 NONCE;"
        + "bit:3 RESERVED;"
        + "bit:4 HLEN;"
        + "bit:1 FIN;"
        + "bit:1 SYN;"
        + "bit:1 RST;"
        + "bit:1 PSH;"
        + "bit:1 ACK;"
        + "bit:1 URG;"
        + "bit:1 ECNECHO;"
        + "bit:1 CWR;"
        + "ushort WindowSize;"
        + "ushort TCPCheckSum;"
        + "ushort UrgentPointer;"
        + "byte [HLEN*4-20] Option;"
        + "byte [_] Data;");

    byte[] testArray;
    try (InputStream inStream = getResourceAsInputStream("tcppacket.bin")) {
      testArray = new JBBPBitInputStream(inStream).readByteArray(-1);
      assertEquals(173, testArray.length);
    }

    final byte[] theData = testArray;

    final AtomicInteger errorCounter = new AtomicInteger();
    final AtomicLong parsingCounter = new AtomicLong();

    final int ITERATIONS = 1000;

    final Runnable test = () -> {
      for (int i = 0; i < ITERATIONS; i++) {
        try {
          Thread.sleep(System.nanoTime() & 0xF);
          final byte[] ippacket = parserTCP.parse(theData).findFieldForNameAndType("Data", JBBPFieldArrayByte.class).getArray();
          assertEquals(119, ippacket.length);
          final byte[] optionsip = parserIP.parse(ippacket).findFieldForNameAndType("Options", JBBPFieldArrayByte.class).getArray();
          assertEquals(4, optionsip.length);
          parsingCounter.incrementAndGet();
        } catch (Exception ex) {
          ex.printStackTrace();
          errorCounter.incrementAndGet();
        }
      }
    };

    final Thread[] threads = new Thread[15];

    for (int i = 0; i < threads.length; i++) {
      final Thread testThread = new Thread(test, "jbbp_test_thread" + i);
      testThread.setDaemon(true);
      threads[i] = testThread;
      testThread.start();
    }

    for (final Thread t : threads) {
      t.join();
    }

    assertEquals(threads.length * ITERATIONS, parsingCounter.get());
    assertEquals(0, errorCounter.get());
  }

/**
   * Case 28-jul-2016
   * Simultaneous usage of expression evaluator from multiple threads.
   *
   * Issue #10, assertArrayLength throws exception in multi-thread
   *
   * @throws Exception for any error
   */
  @Test
  public void testMutlithredUsageOfParser() throws Exception {
    final JBBPParser parserIP = JBBPParser.prepare("skip:14; // skip bytes till the frame\n"
        + "bit:4 InternetHeaderLength;"
        + "bit:4 Version;"
        + "bit:2 ECN;"
        + "bit:6 DSCP;"
        + "ushort TotalPacketLength;"
        + "ushort Identification;"
        + "bit:8 IPFlagsAndFragmentOffset_low;"
        + "bit:5 IPFlagsAndFragmentOffset_high;"
        + "bit:1 MoreFragment;"
        + "bit:1 DonotFragment;"
        + "bit:1 ReservedBit;"
        + "ubyte TTL;"
        + "ubyte Protocol;"
        + "ushort HeaderChecksum;"
        + "int SourceAddress;"
        + "int DestinationAddress;"
        + "byte [(InternetHeaderLength-5)*4] Options;");

    final JBBPParser parserTCP = JBBPParser.prepare("skip:34; // skip bytes till the frame\n"
        + "ushort SourcePort;"
        + "ushort DestinationPort;"
        + "int SequenceNumber;"
        + "int AcknowledgementNumber;"
        + "bit:1 NONCE;"
        + "bit:3 RESERVED;"
        + "bit:4 HLEN;"
        + "bit:1 FIN;"
        + "bit:1 SYN;"
        + "bit:1 RST;"
        + "bit:1 PSH;"
        + "bit:1 ACK;"
        + "bit:1 URG;"
        + "bit:1 ECNECHO;"
        + "bit:1 CWR;"
        + "ushort WindowSize;"
        + "ushort TCPCheckSum;"
        + "ushort UrgentPointer;"
        + "byte [HLEN*4-20] Option;"
        + "byte [_] Data;");

    InputStream inStream = getResourceAsInputStream("tcppacket.bin");
    byte[] testArray;
    try {
      testArray = new JBBPBitInputStream(inStream).readByteArray(-1);
      assertEquals(173, testArray.length);
    } finally {
      inStream.close();
    }

    final byte[] theData = testArray;

    final AtomicInteger errorCounter = new AtomicInteger();
    final AtomicLong parsingCounter = new AtomicLong();

    final int ITERATIONS = 1000;

    final Runnable test = new Runnable() {
      @Override
      public void run() {
        for (int i = 0; i < ITERATIONS; i++) {
          try {
            Thread.sleep(System.nanoTime() & 0xF);
            final byte[] ippacket = parserTCP.parse(theData).findFieldForNameAndType("Data", JBBPFieldArrayByte.class).getArray();
            assertEquals(119, ippacket.length);
            final byte[] optionsip = parserIP.parse(ippacket).findFieldForNameAndType("Options", JBBPFieldArrayByte.class).getArray();
            assertEquals(4, optionsip.length);
            parsingCounter.incrementAndGet();
          } catch (Exception ex) {
            ex.printStackTrace();
            errorCounter.incrementAndGet();
          }
        }
      }
    };

    final Thread[] threads = new Thread[15];

    for (int i = 0; i < threads.length; i++) {
      final Thread testThread = new Thread(test, "jbbp_test_thread" + i);
      testThread.setDaemon(true);
      threads[i] = testThread;
      testThread.start();
    }

    for (final Thread t : threads) {
      t.join();
    }

    assertEquals(threads.length * ITERATIONS, parsingCounter.get());
    assertEquals(0, errorCounter.get());
  }

Replace Anonymous With Lambda com.igormaznitsa.jbbp.it.BasedOnQuestionsAndCasesTest.testMutlithredUsageOfParser.test.new Runnable with () -> {for(int i=0; i < ITERATIONS; i++){tryThread.sleep(System.nanoTime() & 0xF); in method public testMutlithredUsageOfParser() : void from class com.igormaznitsa.jbbp.it.BasedOnQuestionsAndCasesTest