You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by sz...@apache.org on 2007/09/30 21:03:30 UTC
svn commit: r580770 - in
/directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages:
./ NtpTimeStampTest.java
Author: szoerner
Date: Sun Sep 30 12:03:28 2007
New Revision: 580770
URL: http://svn.apache.org/viewvc?rev=580770&view=rev
Log:
Tests for class NtpTimeStamp added.
Added:
directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/
directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java
Added: directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java?rev=580770&view=auto
==============================================================================
--- directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java (added)
+++ directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages/NtpTimeStampTest.java Sun Sep 30 12:03:28 2007
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.apache.directory.server.ntp.messages;
+
+
+import java.nio.ByteBuffer;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Some unit tests for NtpTimeStamp.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: $, $Date: $
+ */
+public class NtpTimeStampTest extends TestCase
+{
+ private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat( "MM/dd/yyyy HH:mm:ss" );
+
+
+ /**
+ * equals() should return false for NtpTimeStamps of date objects with different values.
+ */
+ public void testEqualsForDifferent() throws ParseException
+ {
+
+ Date date = DATE_FORMAT.parse( "04/12/1971 11:23:14" );
+ Date otherDate = DATE_FORMAT.parse( "12/24/2002 15:11:11" );
+
+ assertFalse( date == otherDate );
+ assertFalse( date.equals( otherDate ) );
+
+ NtpTimeStamp timeStamp = new NtpTimeStamp( date );
+ NtpTimeStamp otherTimeStamp = new NtpTimeStamp( otherDate );
+
+ assertFalse( "equals()", timeStamp.equals( otherTimeStamp ) );
+ }
+
+
+ /**
+ * equals() should return true for NtpTimeStamps of date objects with same value.
+ */
+ public void testEqualsForSame() throws ParseException
+ {
+
+ Date date = DATE_FORMAT.parse( "05/30/1978 04:11:02" );
+ Date sameDate = DATE_FORMAT.parse( "05/30/1978 04:11:02" );
+
+ assertFalse( date == sameDate );
+ assertTrue( date.equals( sameDate ) );
+
+ NtpTimeStamp timeStamp = new NtpTimeStamp( date );
+ NtpTimeStamp otherTimeStamp = new NtpTimeStamp( sameDate );
+
+ assertTrue( "equals()", timeStamp.equals( otherTimeStamp ) );
+
+ }
+
+
+ /**
+ * A roundtrip of wrapping a date into a NtpTimeStamp object A, writing it to a buffer, and creating
+ * another NtpTimeStamp B from this buffer, should lead to objects A and B with the same content.
+ */
+ public void testWriteToBuffer() throws ParseException
+ {
+ Date date = DATE_FORMAT.parse( "04/12/1971 11:23:14" );
+
+ NtpTimeStamp timeStampA = new NtpTimeStamp( date );
+
+ ByteBuffer buffer = ByteBuffer.allocate( 1024 );
+ timeStampA.writeTo( buffer );
+ buffer.rewind();
+
+ NtpTimeStamp timeStampB = new NtpTimeStamp( buffer );
+
+ assertTrue( timeStampA.equals( timeStampB ) );
+ }
+}
Re: svn commit: r580770 - in /directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages: ./ NtpTimeStampTest.java
Posted by Alex Karasulu <ak...@apache.org>.
Yeah I'd be interested in a primer too as well as some general conventions
we should follow
with JUnit4. I guess we will learn and apply new conventions as we go but
any recommendations
are good.
Alex
On 9/30/07, Emmanuel Lecharny <el...@gmail.com> wrote:
>
> Hi Stefan,
>
> just a few things :
>
> 1) as we are using Junit4, you don't need to specify that the class
> extends TestCase
> 2) you just need to add the @Test annotation in front of each test method
> :
> @Test public void testEqualsForDifferent() throws ParseException
> 3) To do so, you will have to add those imports :
> import org.junit.Test;
> 4) For setUp and tearDown, add @Before and @After in front of them
> 5) The metjod names don't anymore have to start with 'test', but I
> think it's a good politic to keep this prefix
> 6) For assertXXX, just add
> import static org.junit.Assert.assertXXX; (static is important)
> 7)SimpleDateFormat is not synchronized. In case JUnit launch tests in
> // (not really the case right now, but in the next version ...), you
> might be surprised ;)
>
> Emmanuel
>
> PS: I guess that a page on the developper wiki about Junit4 usgae
> could have helped ...
>
> --
> Regards,
> Cordialement,
> Emmanuel Lécharny
> www.iktek.com
>
Re: svn commit: r580770 - in /directory/apacheds/trunk/protocol-ntp/src/test/java/org/apache/directory/server/ntp/messages: ./ NtpTimeStampTest.java
Posted by Emmanuel Lecharny <el...@gmail.com>.
Hi Stefan,
just a few things :
1) as we are using Junit4, you don't need to specify that the class
extends TestCase
2) you just need to add the @Test annotation in front of each test method :
@Test public void testEqualsForDifferent() throws ParseException
3) To do so, you will have to add those imports :
import org.junit.Test;
4) For setUp and tearDown, add @Before and @After in front of them
5) The metjod names don't anymore have to start with 'test', but I
think it's a good politic to keep this prefix
6) For assertXXX, just add
import static org.junit.Assert.assertXXX; (static is important)
7)SimpleDateFormat is not synchronized. In case JUnit launch tests in
// (not really the case right now, but in the next version ...), you
might be surprised ;)
Emmanuel
PS: I guess that a page on the developper wiki about Junit4 usgae
could have helped ...
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com