@@ -0,0 +1,3510 @@
+/*%0A * Licensed to the University of California, Berkeley under one or more contributor license%0A * agreements. See the NOTICE file distributed with this work for additional information regarding%0A * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the%0A * %22License%22); you may not use this file except in compliance with the License. You may obtain a%0A * copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software distributed under the License%0A * is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express%0A * or implied. See the License for the specific language governing permissions and limitations under%0A * the License.%0A */%0A%0Apackage tachyon.master.journal;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.Mockito;%0Aimport org.powermock.api.mockito.PowerMockito;%0Aimport org.powermock.core.classloader.annotations.PrepareForTest;%0Aimport org.powermock.modules.junit4.PowerMockRunner;%0A%0Aimport com.google.protobuf.Message;%0Aimport com.google.protobuf.UnknownFieldSet;%0Aimport com.google.protobuf.UnknownFieldSet.Field;%0A%0Aimport tachyon.exception.ExceptionMessage;%0Aimport tachyon.proto.JournalEntryProtos;%0Aimport tachyon.proto.JournalEntryProtos.AddMountPointEntry;%0Aimport tachyon.proto.JournalEntryProtos.JournalEntry;%0Aimport tachyon.proto.JournalEntryProtos.JournalEntry.EntryCase;%0A%0A/**%0A * Tests for %7B@link JournalUtils%7D.%0A */%0A@RunWith(PowerMockRunner.class)%0A@PrepareForTest(JournalEntryProtos.JournalEntry.class)%0Apublic final class JournalProtoUtilsTest %7B%0A%0A  /**%0A   * Tests that getMessage returns the sub-message contained in a JournalEntry.%0A   */%0A  @Test%0A  public void getMessageTest() %7B%0A    AddMountPointEntry addMountEntry = AddMountPointEntry.newBuilder().build();%0A    tachyon.proto.JournalEntryProtos.JournalEntry entry =%0A        JournalEntryProtos.JournalEntry.newBuilder().setAddMountPoint(addMountEntry).build();%0A    Message message = JournalProtoUtils.getMessage(entry);%0A    Assert.assertTrue(message instanceof AddMountPointEntry);%0A    Assert.assertEquals(message, addMountEntry);%0A  %7D%0A%0A  /**%0A   * Tests that the right exception is thrown when no sub-message is set for a JournalEntry.%0A   */%0A  @Test%0A  public void getNoMessageTest() %7B%0A    tachyon.proto.JournalEntryProtos.JournalEntry entry =%0A        JournalEntryProtos.JournalEntry.newBuilder().build();%0A    try %7B%0A      JournalProtoUtils.getMessage(entry);%0A      Assert.fail(%22getMessage() should fail when no messages is set%22);%0A    %7D catch (RuntimeException e) %7B%0A      Assert.assertEquals(ExceptionMessage.NO_ENTRY_TYPE.getMessage(%22%5B%5D%22), e.getMessage());%0A    %7D%0A  %7D%0A%0A  /**%0A   * Uses Powermock to test that unknown fields are reported when no journal sub-message is%0A   * recognized.%0A   */%0A  @Test%0A  public void getUnknownMessageTest() %7B%0A    JournalEntry unknownEntry = PowerMockito.mock(JournalEntryProtos.JournalEntry.class);%0A    Mockito.when(unknownEntry.getUnknownFields()).thenReturn(%0A        UnknownFieldSet.newBuilder().addField(46264, Field.newBuilder().build()).build());%0A    Mockito.when(unknownEntry.getEntryCase()).thenReturn(EntryCase.ENTRY_NOT_SET);%0A    try %7B%0A      JournalProtoUtils.getMessage(unknownEntry);%0A      Assert.fail(%22getMessage() should fail when no messages is set%22);%0A    %7D catch (RuntimeException e) %7B%0A      Assert.assertEquals(ExceptionMessage.NO_ENTRY_TYPE.getMessage(%22%5B46264%5D%22), e.getMessage());%0A    %7D%0A  %7D%0A%7D%0A

Add tests for JournalProtoUtils