/*
 * This file is part of dependency-check-core.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright (c) 2015 The OWASP Foundatio. All Rights Reserved.
 */
package org.owasp.dependencycheck.analyzer;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.owasp.dependencycheck.BaseDBTestCase;
import org.owasp.dependencycheck.BaseTest;
import org.owasp.dependencycheck.Engine;
import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
import org.owasp.dependencycheck.dependency.Dependency;

import java.io.File;
import org.apache.commons.lang3.ArrayUtils;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;

/**
 * Unit tests for NodePackageAnalyzer.
 *
 * @author Dale Visser
 */
public class ComposerLockAnalyzerTest extends BaseDBTestCase {

    /**
     * The analyzer to test.
     */
    private ComposerLockAnalyzer analyzer;

    /**
     * Correctly setup the analyzer for testing.
     *
     * @throws Exception thrown if there is a problem
     */
    @Before
    @Override
    public void setUp() throws Exception {
        super.setUp();
        analyzer = new ComposerLockAnalyzer();
        analyzer.initialize(getSettings());
        analyzer.setFilesMatched(true);
        analyzer.prepare(null);
    }

    /**
     * Cleanup the analyzer's temp files, etc.
     *
     * @throws Exception thrown if there is a problem
     */
    @After
    @Override
    public void tearDown() throws Exception {
        analyzer.close();
        super.tearDown();
    }

    /**
     * Test of getName method, of class ComposerLockAnalyzer.
     */
    @Test
    public void testGetName() {
        assertEquals("Composer.lock analyzer", analyzer.getName());
    }

    /**
     * Test of supportsExtension method, of class ComposerLockAnalyzer.
     */
    @Test
    public void testSupportsFiles() {
        assertTrue(analyzer.accept(new File("composer.lock")));
    }

    /**
     * Test of inspect method, of class PythonDistributionAnalyzer.
     *
     * @throws AnalysisException is thrown when an exception occurs.
     */
    @Test
    public void testAnalyzePackageJson() throws Exception {
        try (Engine engine = new Engine(getSettings())) {
            final Dependency result = new Dependency(BaseTest.getResourceAsFile(this,
                    "composer.lock"));
            //simulate normal operation when the composer.lock is already added to the engine as a dependency
            engine.addDependency(result);
            analyzer.analyze(result, engine);
            //make sure the redundant composer.lock is removed
            assertFalse(ArrayUtils.contains(engine.getDependencies(), result));
            assertEquals(30, engine.getDependencies().length);
            Dependency d = engine.getDependencies()[0];
            assertEquals("classpreloader", d.getName());
            assertEquals("2.0.0", d.getVersion());
            assertThat(d.getDisplayFileName(), equalTo("classpreloader:2.0.0"));
            assertEquals(ComposerLockAnalyzer.DEPENDENCY_ECOSYSTEM, d.getEcosystem());
        }
    }
}

@@ -1138,212 +1138,65 @@
 org.
-junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.assertThat;%0Aimport static org.hamcrest.CoreMatchers.equalTo
+hamcrest.CoreMatchers.*;%0Aimport static org.junit.Assert.*
 ;%0A%0A/
@@ -3293,16 +3293,56 @@
         
+boolean found = false;%0A            for (
 Dependen
@@ -3346,17 +3346,17 @@
 dency d 
-=
+:
  engine.
@@ -3376,12 +3376,11 @@
 es()
-%5B0%5D;
+) %7B
 %0A   
@@ -3388,28 +3388,23 @@
         
-assertEquals
+    if 
 (%22classp
@@ -3412,18 +3412,24 @@
 eloader%22
-, 
+.equals(
 d.getNam
@@ -3428,26 +3428,66 @@
 d.getName())
-;%0A
+) %7B%0A                    found = true;%0A    
             
@@ -3478,32 +3478,36 @@
                 
+    
 assertEquals(%222.
@@ -3525,24 +3525,32 @@
 Version());%0A
+        
             
@@ -3622,32 +3622,40 @@
 ));%0A            
+   
+     
 assertEquals(Com
@@ -3709,24 +3709,121 @@
 osystem());%0A
+                %7D%0A            %7D%0A            assertTrue(%22Expeced to find classpreloader%22, found);%0A
         %7D%0A  

make test case more flexible