/*
 * Copyright (c) 2017 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockito.internal.junit;

import java.util.Arrays;
import org.junit.Test;
import org.mockito.internal.invocation.InvocationBuilder;
import org.mockito.internal.stubbing.StubbedInvocationMatcher;
import org.mockito.internal.util.SimpleMockitoLogger;
import org.mockito.stubbing.Stubbing;
import org.mockitoutil.TestBase;

import static org.junit.Assert.assertEquals;
import static org.mockito.internal.stubbing.answers.DoesNothing.doesNothing;

public class UnusedStubbingsTest extends TestBase {

    SimpleMockitoLogger logger = new SimpleMockitoLogger();

    @Test
    public void no_unused_stubbings() throws Exception {
        //given
        UnusedStubbings stubbings = new UnusedStubbings(Arrays.<Stubbing> asList());

        //when
        stubbings.format("MyTest.myTestMethod", logger);

        //then
        assertEquals("", logger.getLoggedInfo());
    }

    @Test
    public void unused_stubbings() throws Exception {
        //given
        UnusedStubbings stubbings = new UnusedStubbings(Arrays.asList(
            new StubbedInvocationMatcher(new InvocationBuilder().toInvocationMatcher(), doesNothing()),
            new StubbedInvocationMatcher(new InvocationBuilder().toInvocationMatcher(), doesNothing())
        ));


        //when
        stubbings.format("MyTest.myTestMethod", logger);

        //then
        assertEquals(
                "[MockitoHint] MyTest.myTestMethod (see javadoc for MockitoHint):\n" +
                        "[MockitoHint] 1. Unused -> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" +
                        "[MockitoHint] 2. Unused -> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n",
                filterLineNo(logger.getLoggedInfo()));
    }
}

@@ -175,16 +175,47 @@
 Arrays;%0A
+import java.util.Collections;%0A%0A
 import o
@@ -229,16 +229,16 @@
 t.Test;%0A
-
 import o
@@ -476,16 +476,74 @@
 tBase;%0A%0A
+import static org.assertj.core.api.Assertions.assertThat;%0A
 import s
@@ -714,16 +714,24 @@
  %7B%0A%0A    
+private 
 SimpleMo
@@ -918,21 +918,26 @@
 ubbings(
-Array
+Collection
 s.%3CStubb
@@ -940,19 +940,21 @@
 tubbing%3E
- as
+empty
 List());
@@ -1578,20 +1578,57 @@
 sert
-Equals(%0A    
+That(filterLineNo(logger.getLoggedInfo())).isIn(%0A
     
@@ -1701,25 +1701,48 @@
 oHint):%5Cn%22 +
-%0A
+  //Java %3C9%0A            
             
@@ -1865,32 +1865,44 @@
                 
+            
 %22%5BMockitoHint%5D 2
@@ -1996,48 +1996,397 @@
     
-    filterLineNo(logger.getLoggedInfo())
+%22%5BMockitoHint%5D MyTest.myTestMethod (see javadoc for MockitoHint):%5Cn%22 +  //Java 9%0A                                    %22%5BMockitoHint%5D 1. Unused -%3E at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)%5Cn%22 +%0A                                    %22%5BMockitoHint%5D 2. Unused -%3E at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)%5Cn%22%0A        
 );%0A 

Fix another test failing with Java 9