Consolidate parsing and formatting for label votes
We currently support two styles of parsing, Label-Value and Label=Value. Consolidate these into a single LabelVote class. (Unfortunately for backwards-compatibility reasons we can't just eliminate Label=Value in ReviewCommand.) Change-Id: I9e5255b184d786226e6b11fe059001608c00673d
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// 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.
|
||||
|
||||
package com.google.gerrit.server.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class LabelVoteTest {
|
||||
@Test
|
||||
public void parse() {
|
||||
LabelVote l;
|
||||
l = LabelVote.parse("Code-Review-2");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) -2, l.getValue());
|
||||
l = LabelVote.parse("Code-Review-1");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) -1, l.getValue());
|
||||
l = LabelVote.parse("-Code-Review");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) 0, l.getValue());
|
||||
l = LabelVote.parse("Code-Review");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) 1, l.getValue());
|
||||
l = LabelVote.parse("Code-Review+2");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) 2, l.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void format() {
|
||||
assertEquals("Code-Review-2", LabelVote.parse("Code-Review-2").format());
|
||||
assertEquals("Code-Review-1", LabelVote.parse("Code-Review-1").format());
|
||||
assertEquals("-Code-Review", LabelVote.parse("-Code-Review").format());
|
||||
assertEquals("Code-Review", LabelVote.parse("Code-Review").format());
|
||||
assertEquals("Code-Review+2", LabelVote.parse("Code-Review+2").format());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWithEquals() {
|
||||
LabelVote l;
|
||||
l = LabelVote.parseWithEquals("Code-Review=-2");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) -2, l.getValue());
|
||||
l = LabelVote.parseWithEquals("Code-Review=-1");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) -1, l.getValue());
|
||||
l = LabelVote.parseWithEquals("Code-Review=0");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) 0, l.getValue());
|
||||
l = LabelVote.parseWithEquals("Code-Review=1");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) 1, l.getValue());
|
||||
l = LabelVote.parseWithEquals("Code-Review=+1");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) 1, l.getValue());
|
||||
l = LabelVote.parseWithEquals("Code-Review=2");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) 2, l.getValue());
|
||||
l = LabelVote.parseWithEquals("Code-Review=+2");
|
||||
assertEquals("Code-Review", l.getLabel());
|
||||
assertEquals((short) 2, l.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formatWithEquals() {
|
||||
assertEquals("Code-Review=-2",
|
||||
LabelVote.parseWithEquals("Code-Review=-2").formatWithEquals());
|
||||
assertEquals("Code-Review=-1",
|
||||
LabelVote.parseWithEquals("Code-Review=-1").formatWithEquals());
|
||||
assertEquals("Code-Review=0",
|
||||
LabelVote.parseWithEquals("Code-Review=0").formatWithEquals());
|
||||
assertEquals("Code-Review=+1",
|
||||
LabelVote.parseWithEquals("Code-Review=+1").formatWithEquals());
|
||||
assertEquals("Code-Review=+2",
|
||||
LabelVote.parseWithEquals("Code-Review=+2").formatWithEquals());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user