/*
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you 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.
 */
package groovy.util.logging.vm9

import groovy.transform.AutoImplement
import groovy.transform.CompileStatic
import groovy.transform.PackageScope

@PackageScope
@AutoImplement
@CompileStatic
class LoggerSpy implements System.Logger {
    String warningParameter = null
    String infoParameter = null
    String traceParameter = null
    String errorParameter = null
    String debugParameter = null

    void reset() {
        warningParameter = null
        infoParameter = null
        traceParameter = null
        errorParameter = null
        debugParameter = null
    }

    @Override
    void log(Level lev, String s) {
        switch (lev) {
            case Level.WARNING:
                if (warningParameter) throwAssertionError("Warning already called once with parameter $warningParameter")
                warningParameter = s
                break
            case Level.INFO:
                if (infoParameter) throwAssertionError("Info already called once with parameter $infoParameter")
                infoParameter = s
                break
            case Level.ERROR:
                if (errorParameter) throwAssertionError("Error already called once with parameter $errorParameter")
                errorParameter = s
                break
            case Level.DEBUG:
                if (debugParameter) throwAssertionError("Debug already called once with parameter $debugParameter")
                debugParameter = s
                break
            case Level.TRACE:
                if (traceParameter) throwAssertionError("Trace already called once with parameter $traceParameter")
                traceParameter = s
                break
        }
    }

    private static void throwAssertionError(Object detailMessage) {
        throw new AssertionError(detailMessage)
    }
}
