package org.opencv.test.objdetect;

import java.util.List;
import org.opencv.core.Mat;
import org.opencv.objdetect.QRCodeDetector;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.test.OpenCVTestCase;
import java.util.ArrayList;

public class QRCodeDetectorTest extends OpenCVTestCase {

    private final static String ENV_OPENCV_TEST_DATA_PATH = "OPENCV_TEST_DATA_PATH";
    private String testDataPath;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        testDataPath = System.getenv(ENV_OPENCV_TEST_DATA_PATH);
        if (testDataPath == null)
            throw new Exception(ENV_OPENCV_TEST_DATA_PATH + " has to be defined!");
    }

    public void testDetectAndDecode() {
        Mat img = Imgcodecs.imread(testDataPath + "/cv/qrcode/link_ocv.jpg");
        assertFalse(img.empty());
        QRCodeDetector detector = new QRCodeDetector();
        assertNotNull(detector);
        String output = detector.detectAndDecode(img);
        assertEquals(output, "https://opencv.org/");
    }

    public void testDetectAndDecodeMulti() {
        Mat img = Imgcodecs.imread(testDataPath + "/cv/qrcode/multiple/6_qrcodes.png");
        assertFalse(img.empty());
        QRCodeDetector detector = new QRCodeDetector();
        assertNotNull(detector);
        List < String > output = new ArrayList< String >();
        boolean result = detector.detectAndDecodeMulti(img, output);
        assertTrue(result);
        assertEquals(output.size(), 6);
        assertEquals(output.get(0), "SKIP");
        assertEquals(output.get(1), "EXTRA");
        assertEquals(output.get(2), "TWO STEPS FORWARD");
        assertEquals(output.get(3), "STEP BACK");
        assertEquals(output.get(4), "QUESTION");
        assertEquals(output.get(5), "STEP FORWARD");
    }
}

@@ -220,24 +220,98 @@
 a.util.Array
+s;%0Aimport java.util.ArrayList;%0Aimport java.util.HashSet;%0Aimport java.util.
 List;%0A%0Apubli
@@ -1577,298 +1577,222 @@
     
-assertEquals(output.get(0), %22SKIP%22);%0A        assertEquals(output.get(1), %22EXTRA%22);%0A        assertEquals(output.get(2), %22TWO STEPS FORWARD%22);%0A        assertEquals(output.get(3), %22STEP BACK%22);%0A        assertEquals(output.get(4), %22QUESTION%22);%0A        assertEquals(output.get(5), %22STEP FORWARD%22
+List %3C String %3E expectedResults = Arrays.asList(%22SKIP%22, %22EXTRA%22, %22TWO STEPS FORWARD%22, %22STEP BACK%22, %22QUESTION%22, %22STEP FORWARD%22);%0A        assertEquals(new HashSet%3CString%3E(output), new HashSet%3CString%3E(expectedResults)
 );%0A 

Fix for failing QRCodeDetectorTest.testDetectAndDecodeMulti test