/* Copyright Unidata */
package ucar.nc2.grib;

import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import thredds.inventory.CollectionUpdateType;
import ucar.nc2.grib.grib1.Grib1Index;
import ucar.nc2.grib.grib2.Grib2Index;
import java.lang.invoke.MethodHandles;
import java.util.ArrayList;
import java.util.List;

/**
 * Test can read both proto2 and proto3 gbx9.
 * Also test failure mode for invalid proto.
 *
 * @author caron
 * @since 11/28/2015.
 */
@RunWith(Parameterized.class)
public class TestGribIndexProto {
  private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());

  @Parameterized.Parameters(name = "{0}")
  public static List<Object[]> getTestParameters() {
    List<Object[]> result = new ArrayList<>();
    result.add(new Object[] {"grib1.proto2.gbx9", true, false});
    result.add(new Object[] {"grib1.proto3.gbx9", true, true}); // fails
    result.add(new Object[] {"grib1.proto3.syntax2.gbx9", true, false});
    result.add(new Object[] {"grib2.proto2.gbx9", false, false});
    result.add(new Object[] {"grib2.proto3.gbx9", false, true}); // fails
    result.add(new Object[] {"grib2.proto3.syntax2.gbx9", false, false});
    return result;
  }

  String filename;
  boolean isGrib1;
  boolean fail;

  public TestGribIndexProto(String ds, boolean isGrib1, boolean fail) {
    this.filename = "../grib/src/test/data/index/" + ds;
    this.isGrib1 = isGrib1;
    this.fail = fail;
  }

  @Test
  public void testOpen() {
    try {
      if (isGrib1) {
        Grib1Index reader = new Grib1Index();
        boolean ok = reader.readIndex(filename, -1, CollectionUpdateType.never);
        assertTrue(ok || fail);
      } else {
        Grib2Index reader = new Grib2Index();
        boolean ok = reader.readIndex(filename, -1, CollectionUpdateType.never);
        assertTrue(ok || fail);
      }
    } catch (Exception e) {
      fail("Exception should not be thrown");
    }
  }
}


@@ -942,36 +942,35 @@
 o2.gbx9%22, true, 
-fals
+tru
 e%7D);%0A    result.
@@ -1013,33 +1013,25 @@
 %22, true,
- true%7D); //
  fa
-i
 ls
+e%7D);
 %0A    res
@@ -1079,36 +1079,35 @@
 x2.gbx9%22, true, 
-fals
+tru
 e%7D);%0A    result.
@@ -1144,36 +1144,35 @@
 2.gbx9%22, false, 
-fals
+tru
 e%7D);%0A    result.
@@ -1220,25 +1220,17 @@
 lse,
- true%7D); //
  fa
-i
 ls
+e%7D);
 %0A   
@@ -1283,36 +1283,35 @@
 2.gbx9%22, false, 
-fals
+tru
 e%7D);%0A    return 
@@ -1371,20 +1371,30 @@
 boolean 
-fail
+expectedResult
 ;%0A%0A  pub
@@ -1452,20 +1452,30 @@
 boolean 
-fail
+expectedResult
 ) %7B%0A    
@@ -1568,19 +1568,39 @@
 his.
-fail = fail
+expectedResult = expectedResult
 ;%0A  
@@ -1722,34 +1722,38 @@
         boolean 
-ok
+result
  = reader.readIn
@@ -1809,39 +1809,53 @@
       assert
-True(ok %7C%7C fail
+Equals(expectedResult, result
 );%0A      %7D e
@@ -1922,18 +1922,22 @@
 boolean 
-ok
+result
  = reade
@@ -2009,23 +2009,37 @@
 sert
-True(ok %7C%7C fail
+Equals(expectedResult, result
 );%0A 

Improve test sensitivity and readability (previously it would always pass if it returned true regardless of expected result!)