/** Tests that the Builder constructors return equivalent objects when given the same data. */
 @Test
 public void testTreatmentBuilderConstructors() {
   final TrafficTreatment treatment1 =
       DefaultTrafficTreatment.builder()
           .add(new ModLambdaInstruction(L0SubType.LAMBDA, (short) 4))
           .build();
   final TrafficTreatment treatment2 = DefaultTrafficTreatment.builder(treatment1).build();
   assertThat(treatment1, is(equalTo(treatment2)));
 }
  /** Tests methods defined on the Builder. */
  @Test
  public void testBuilderMethods() {
    final Instruction instruction1 = new ModLambdaInstruction(L0SubType.LAMBDA, (short) 4);

    final TrafficTreatment.Builder builder1 =
        DefaultTrafficTreatment.builder()
            .add(instruction1)
            .setEthDst(MacAddress.BROADCAST)
            .setEthSrc(MacAddress.BROADCAST)
            .setIpDst(IpAddress.valueOf("1.1.1.1"))
            .setIpSrc(IpAddress.valueOf("2.2.2.2"))
            .setLambda((short) 4)
            .setOutput(PortNumber.portNumber(2))
            .setVlanId(VlanId.vlanId((short) 4))
            .setVlanPcp((byte) 3);

    final TrafficTreatment treatment1 = builder1.build();

    final List<Instruction> instructions1 = treatment1.instructions();
    assertThat(instructions1, hasSize(9));

    builder1.drop();
    builder1.add(instruction1);

    final List<Instruction> instructions2 = builder1.build().instructions();
    assertThat(instructions2, hasSize(8));
  }
 /** Tests equals(), hashCode() and toString() methods of DefaultTrafficTreatment. */
 @Test
 public void testEquals() {
   final TrafficTreatment treatment1 =
       DefaultTrafficTreatment.builder()
           .add(new ModLambdaInstruction(L0SubType.LAMBDA, (short) 4))
           .build();
   final TrafficTreatment sameAsTreatment1 =
       DefaultTrafficTreatment.builder()
           .add(new ModLambdaInstruction(L0SubType.LAMBDA, (short) 4))
           .build();
   final TrafficTreatment treatment2 =
       DefaultTrafficTreatment.builder()
           .add(new ModLambdaInstruction(L0SubType.LAMBDA, (short) 2))
           .build();
   new EqualsTester()
       .addEqualityGroup(treatment1, sameAsTreatment1)
       .addEqualityGroup(treatment2)
       .testEquals();
 }