Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert main method to unit test #1414

Merged
merged 1 commit into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2000, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021 Contributors to Eclipse Foundation
* Copyright (c) 2020, 2022 Contributors to Eclipse Foundation
* Copyright (c) 2020 Payara Services Ltd.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -293,30 +293,6 @@ private int getStringDelimiterIndex(String strToken, String delimiter, int fromI
}
}

public static void main(String[] args) throws Exception {

// String str = "imqConsumerFlowThreshold=78,imqAddressList=\"tcp://localhost:7676,tcp://localhost:7677\"";
String str = "imqConsumerFlowThreshold=78,imqAddressList=tcp://localhost:7676\\,tcp://localhost:7677";

System.out.println("Parsing " + str);

String separator = "=";
String delimiter = ",";

CustomTokenizer tokenList = new CustomTokenizer(str, delimiter);

while (tokenList.hasMoreTokens()) {
String propValuePair = tokenList.nextTokenWithoutEscapeAndQuoteChars();

int loc = propValuePair.indexOf(separator);
String propName = propValuePair.substring(0, loc);
String propValue = propValuePair.substring(loc + separator.length());
System.out.println("name=" + propName);
System.out.println("value=" + propValue);
}

}

public static Hashtable<String, String> parseToProperties(String prop) throws InvalidPropertyException {

String separator = "=";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2022 Contributors to Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.messaging.jms.ra.util;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;

import org.junit.jupiter.api.Test;

import jakarta.resource.spi.InvalidPropertyException;

class CustomTokenizerTest {

@Test
void testConvertedFromMainMethod() throws InvalidPropertyException {
String str = "imqConsumerFlowThreshold=78,imqAddressList=tcp://localhost:7676\\,tcp://localhost:7677";
String delimiter = ",";
var tokens = new ArrayList<String>();

CustomTokenizer tokenList = new CustomTokenizer(str, delimiter);
while (tokenList.hasMoreTokens()) {
tokens.add(tokenList.nextTokenWithoutEscapeAndQuoteChars());
}

assertThat(tokens).containsExactly("imqConsumerFlowThreshold=78", "imqAddressList=tcp://localhost:7676,tcp://localhost:7677");
}
}