Skip to content

Commit

Permalink
common: fix ChecksumType.toString()
Browse files Browse the repository at this point in the history
Motivation:
default Enum.toString() returns Enum.name(), which is string of enum, e.g.

MD5_TYPE.toString() -> "MD5_TYPE".

Nevertheless, by converting string form into ChecksumType, we expect
checksum algorithm name. This happens when we read configuration files
and have to create corresponding objects.

Modification:
add ChecksumType.toString() to return type name.

Result:
The correct string form is produced, which is used by various dcache
admin commands and configuration files.

Ticket: #8941
Acked-by: Gerd Behrmann
Target: master, 2.15, 2.14, 2.13, (2.12, 2.11, 2.12).
Require-book: no
Require-notes: no
(cherry picked from commit 047e1d1)
Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
  • Loading branch information
kofemann committed Apr 7, 2016
1 parent 981c9d8 commit b7ab80b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -90,4 +90,10 @@ public int getNibbles()
{
return (bits + 3) / 4;
}

@Override
public String toString()
{
return getName();
}
}
Expand Up @@ -6,7 +6,7 @@
import static org.dcache.util.ChecksumType.MD5_TYPE;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import static org.junit.Assert.assertEquals;

/**
* Tests for the ChecksumType
Expand Down Expand Up @@ -36,4 +36,12 @@ public void shouldReturnCorrectNibblesForMD5()
{
assertThat(MD5_TYPE.getNibbles(), equalTo(32));
}

@Test
public void shouldReturnSimpleNameOnToString() {
for(ChecksumType checksumType: ChecksumType.values()) {
assertEquals(checksumType.getName(), checksumType.toString());
}
}

}

0 comments on commit b7ab80b

Please sign in to comment.