BAEL-5617 Handle classes with the same name in Java (#12676)
* BAEL-5617 Handle classes with the same name in Java code samples * BAEL-5617 Handle classes with the same name in Java update project module
This commit is contained in:
parent
3d17a48aa2
commit
c3204d4a2e
|
@ -0,0 +1,18 @@
|
|||
package com.baeldung.date;
|
||||
|
||||
public class Date {
|
||||
|
||||
private long currentTimeMillis;
|
||||
|
||||
public Date() {
|
||||
this(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public Date(long currentTimeMillis) {
|
||||
this.currentTimeMillis = currentTimeMillis;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return currentTimeMillis;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.baeldung.date;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DateUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenUsingFullyQualifiedClassNames() {
|
||||
|
||||
java.util.Date javaDate = new java.util.Date();
|
||||
com.baeldung.date.Date baeldungDate = new com.baeldung.date.Date(javaDate.getTime());
|
||||
|
||||
Assert.assertEquals(javaDate.getTime(), baeldungDate.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenImportTheMostUsedOne() {
|
||||
|
||||
Date javaDate = new Date();
|
||||
com.baeldung.date.Date baeldungDate = new com.baeldung.date.Date(javaDate.getTime());
|
||||
|
||||
Assert.assertEquals(javaDate.getTime(), baeldungDate.getTime());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue