// Path: enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/NormalizeLineSeparatorReader.java
// public enum LineSeparator
// {
//     WINDOWS( "\r\n", null ), UNIX( "\n", '\r' );
// 
//     private final char[] separatorChars;
// 
//     private final Character notPrecededByChar;
// 
//     LineSeparator( String separator, Character notPrecededByChar )
//     {
//         separatorChars = separator.toCharArray();
//         this.notPrecededByChar = notPrecededByChar;
//     }
// 
//     enum MatchResult
//     {
//         NO_MATCH,
//         POTENTIAL_MATCH,
//         MATCH;
//     }
// 
//     /**
//      * Checks if two given characters match the line separator represented by this object.
//      * @param currentCharacter the character to check against
//      * @param previousCharacter optional previous character (may be {@code null})
//      * @return one of {@link MatchResult}
//      */
//     public MatchResult matches( char currentCharacter, Character previousCharacter )
//     {
//         int len = separatorChars.length;
//         if ( currentCharacter == separatorChars[len - 1] )
//         {
//             if ( len > 1 )
//             {
//                 if ( previousCharacter == null || previousCharacter != separatorChars[len - 1] )
//                 {
//                     return MatchResult.NO_MATCH;
//                 }
//             }
//             if ( notPrecededByChar != null )
//             {
//                 if ( previousCharacter != null && notPrecededByChar == previousCharacter )
//                 {
//                     return MatchResult.NO_MATCH;
//                 }
//             }
//             return MatchResult.MATCH;
//         }
//         else if ( len > 1 && currentCharacter == separatorChars[len - 2] )
//         {
//             return MatchResult.POTENTIAL_MATCH;
//         }
//         return MatchResult.NO_MATCH;
//     }
// };


import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.plugins.enforcer.utils.NormalizeLineSeparatorReader.LineSeparator;
import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
package org.apache.maven.plugins.enforcer;

/*
 * 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.
 */



/**
 * Test the "RequireTextFileChecksum" rule
 */
public class TestRequireTextFileChecksum
{

    private final RequireTextFileChecksum rule = new RequireTextFileChecksum();

    @TempDir
    public File temporaryFolder;

    @Test
    public void testFileChecksumMd5NormalizedFromUnixToWindows()
        throws IOException, EnforcerRuleException
    {
        File f = File.createTempFile( "junit", null, temporaryFolder );
        FileUtils.fileWrite( f, "line1\nline2\n" );

        rule.setFile( f );
        rule.setChecksum( "c6242222cf6ccdb15a43e0e5b1a08810" );
        rule.setType( "md5" );
// Path: enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/utils/NormalizeLineSeparatorReader.java
// public enum LineSeparator
// {
//     WINDOWS( "\r\n", null ), UNIX( "\n", '\r' );
// 
//     private final char[] separatorChars;
// 
//     private final Character notPrecededByChar;
// 
//     LineSeparator( String separator, Character notPrecededByChar )
//     {
//         separatorChars = separator.toCharArray();
//         this.notPrecededByChar = notPrecededByChar;
//     }
// 
//     enum MatchResult
//     {
//         NO_MATCH,
//         POTENTIAL_MATCH,
//         MATCH;
//     }
// 
//     /**
//      * Checks if two given characters match the line separator represented by this object.
//      * @param currentCharacter the character to check against
//      * @param previousCharacter optional previous character (may be {@code null})
//      * @return one of {@link MatchResult}
//      */
//     public MatchResult matches( char currentCharacter, Character previousCharacter )
//     {
//         int len = separatorChars.length;
//         if ( currentCharacter == separatorChars[len - 1] )
//         {
//             if ( len > 1 )
//             {
//                 if ( previousCharacter == null || previousCharacter != separatorChars[len - 1] )
//                 {
//                     return MatchResult.NO_MATCH;
//                 }
//             }
//             if ( notPrecededByChar != null )
//             {
//                 if ( previousCharacter != null && notPrecededByChar == previousCharacter )
//                 {
//                     return MatchResult.NO_MATCH;
//                 }
//             }
//             return MatchResult.MATCH;
//         }
//         else if ( len > 1 && currentCharacter == separatorChars[len - 2] )
//         {
//             return MatchResult.POTENTIAL_MATCH;
//         }
//         return MatchResult.NO_MATCH;
//     }
// };


// Path: enforcer-rules/src/test/java/org/apache/maven/plugins/enforcer/TestRequireTextFileChecksum.java
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
import org.apache.maven.plugins.enforcer.utils.NormalizeLineSeparatorReader.LineSeparator;
import org.codehaus.plexus.util.FileUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

package org.apache.maven.plugins.enforcer;

/*
 * 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.
 */



/**
 * Test the "RequireTextFileChecksum" rule
 */
public class TestRequireTextFileChecksum
{

    private final RequireTextFileChecksum rule = new RequireTextFileChecksum();

    @TempDir
    public File temporaryFolder;

    @Test
    public void testFileChecksumMd5NormalizedFromUnixToWindows()
        throws IOException, EnforcerRuleException
    {
        File f = File.createTempFile( "junit", null, temporaryFolder );
        FileUtils.fileWrite( f, "line1\nline2\n" );

        rule.setFile( f );
        rule.setChecksum( "c6242222cf6ccdb15a43e0e5b1a08810" );
        rule.setType( "md5" );
        rule.setNormalizeLineSeparatorTo( LineSeparator.WINDOWS );