-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added equals and hashcode. Changed code to catch an empty String (#897)
Signed-off-by: dhoard <doug.hoard@gmail.com>
- Loading branch information
Showing
2 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/snapshots/UnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.prometheus.metrics.model.snapshots; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
public class UnitTest { | ||
|
||
@Test | ||
public void testEmpty() { | ||
try { | ||
new Unit(" "); | ||
fail("Expected IllegalArgumentException"); | ||
} catch (IllegalArgumentException e) { | ||
// Expected | ||
} | ||
} | ||
|
||
@Test | ||
public void testEquals1() { | ||
Unit unit1 = Unit.BYTES; | ||
Unit unit2 = new Unit("bytes"); | ||
|
||
Assert.assertEquals(unit2, unit1); | ||
} | ||
|
||
@Test | ||
public void testEquals2() { | ||
Unit unit1 = new Unit("bytes "); | ||
Unit unit2 = new Unit("bytes"); | ||
|
||
Assert.assertEquals(unit2, unit1); | ||
} | ||
|
||
@Test | ||
public void testEquals3() { | ||
Unit unit1 = new Unit(" bytes"); | ||
Unit unit2 = new Unit("bytes"); | ||
|
||
Assert.assertEquals(unit2, unit1); | ||
} | ||
|
||
@Test | ||
public void testEquals4() { | ||
Unit unit1 = new Unit(" bytes "); | ||
Unit unit2 = new Unit("bytes"); | ||
|
||
Assert.assertEquals(unit2, unit1); | ||
} | ||
} |