88import org .esa .snap .core .gpf .GPF ;
99import org .esa .snap .core .gpf .OperatorException ;
1010import org .esa .snap .core .transform .MathTransform2D ;
11+ import org .esa .snap .core .util .DummyProductBuilder ;
1112import org .junit .Test ;
1213
1314import java .util .Date ;
1415import java .util .HashMap ;
1516import java .util .Map ;
1617
17- import static junit .framework .Assert .assertEquals ;
18- import static junit .framework .Assert .assertFalse ;
19- import static junit .framework .Assert .fail ;
20- import static org .junit .Assert .assertNotNull ;
21- import static org .junit .Assert .assertTrue ;
18+ import static org .junit .Assert .*;
2219
2320/**
2421 * @author Tonio Fincke
@@ -44,7 +41,7 @@ public void testTimeInformationIsPreserved() {
4441 assertEquals (startTime .getAsDate ().getTime (), resampledProduct .getStartTime ().getAsDate ().getTime ());
4542 assertEquals (endTime .getAsDate ().getTime (), resampledProduct .getEndTime ().getAsDate ().getTime ());
4643 assertNotNull (resampledProduct .getSceneTimeCoding ());
47- assertEquals (endTime .getMJD (), resampledProduct .getSceneTimeCoding ().getMJD (new PixelPos (0 , 1 )));
44+ assertEquals (endTime .getMJD (), resampledProduct .getSceneTimeCoding ().getMJD (new PixelPos (0 , 1 )), 1.0e-6 );
4845 }
4946
5047 @ Test
@@ -141,4 +138,46 @@ public void testBothTargetWidthAndHeightAreSet() {
141138 assertEquals ("If targetHeight is set, targetWidth must be set, too." , oe .getMessage ());
142139 }
143140 }
141+
142+ @ Test
143+ public void testCreateMaskedImage () {
144+ // It was reported that createMaskedImage can produce a NullPointerException.
145+ // Could not reproduce with this test.
146+ // Exception stack trace is:
147+ // java.lang.NullPointerException
148+ // at org.esa.snap.core.gpf.common.resample.ResamplingOp$1.createImage(ResamplingOp.java:450)
149+ // at com.bc.ceres.glevel.support.AbstractMultiLevelSource.getImage(AbstractMultiLevelSource.java:65)
150+ // at com.bc.ceres.glevel.support.DefaultMultiLevelImage.<init>(DefaultMultiLevelImage.java:45)
151+ // at org.esa.snap.core.gpf.common.resample.ResamplingOp.replaceInvalidValuesByNaN(ResamplingOp.java:446)
152+ // at org.esa.snap.core.gpf.common.resample.ResamplingOp.createMaskedImage(ResamplingOp.java:434)
153+ // at org.esa.snap.core.gpf.common.resample.ResamplingOp.resampleBands(ResamplingOp.java:380)
154+ DummyProductBuilder builder = new DummyProductBuilder ();
155+ builder .size (DummyProductBuilder .Size .MEDIUM );
156+ Product product = builder .create ();
157+
158+ Band noValidationBand = product .addBand ("noValidationBand" , "X" , ProductData .TYPE_INT16 );
159+ ResamplingOp .createMaskedImage (noValidationBand , Float .NaN );
160+
161+ Band noDataBand = product .addBand ("noDataBand" , "X" , ProductData .TYPE_INT16 );
162+ noDataBand .setNoDataValue (5 );
163+ noDataBand .setNoDataValueUsed (true );
164+ ResamplingOp .createMaskedImage (noDataBand , Float .NaN );
165+
166+ Band expressionBand = product .addBand ("expressionBand" , "X" , ProductData .TYPE_INT16 );
167+ expressionBand .setValidPixelExpression ("expressionBand == 6" );
168+ ResamplingOp .createMaskedImage (expressionBand , Float .NaN );
169+
170+ Band noDataExpressionBand = product .addBand ("noDataExpressionBand" , "X" , ProductData .TYPE_INT16 );
171+ noDataExpressionBand .setNoDataValue (5 );
172+ noDataExpressionBand .setNoDataValueUsed (true );
173+ noDataExpressionBand .setValidPixelExpression ("expressionBand == 6" );
174+ ResamplingOp .createMaskedImage (noDataExpressionBand , Float .NaN );
175+
176+ Band badExpressionBand = product .addBand ("badExpressionBand" , "X" , ProductData .TYPE_INT16 );
177+ Band tempNotExisting = product .addBand ("notExisting" , "Y" , ProductData .TYPE_INT16 );
178+ badExpressionBand .setValidPixelExpression ("notExisting == 6" );
179+ badExpressionBand .getValidMaskImage ();
180+ product .removeBand (tempNotExisting );
181+ ResamplingOp .createMaskedImage (badExpressionBand , Float .NaN );
182+ }
144183}
0 commit comments