Skip to content

Commit

Permalink
Fixed date/time rendering issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ekuefler committed Apr 21, 2014
1 parent 26f4aa6 commit c5465ca
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Expand Up @@ -20,12 +20,14 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.GWTBridge;
import com.google.gwt.i18n.client.Messages;
import com.google.gwt.i18n.client.impl.LocaleInfoImpl;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwtmockito.fakes.FakeClientBundleProvider;
import com.google.gwtmockito.fakes.FakeLocaleInfoImplProvider;
import com.google.gwtmockito.fakes.FakeMessagesProvider;
import com.google.gwtmockito.fakes.FakeProvider;
import com.google.gwtmockito.fakes.FakeUiBinderProvider;
Expand Down Expand Up @@ -94,6 +96,7 @@ public class GwtMockito {
static {
DEFAULT_FAKE_PROVIDERS.put(ClientBundle.class, new FakeClientBundleProvider());
DEFAULT_FAKE_PROVIDERS.put(CssResource.class, new FakeMessagesProvider<CssResource>());
DEFAULT_FAKE_PROVIDERS.put(LocaleInfoImpl.class, new FakeLocaleInfoImplProvider());
DEFAULT_FAKE_PROVIDERS.put(Messages.class, new FakeMessagesProvider<Messages>());
DEFAULT_FAKE_PROVIDERS.put(
SafeHtmlTemplates.class, new FakeMessagesProvider<SafeHtmlTemplates>());
Expand Down
@@ -0,0 +1,38 @@
/*
* Copyright 2014 Google Inc.
*
* Licensed 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 com.google.gwtmockito.fakes;

import com.google.gwt.i18n.client.DateTimeFormatInfo;
import com.google.gwt.i18n.client.DefaultDateTimeFormatInfo;
import com.google.gwt.i18n.client.impl.LocaleInfoImpl;

/**
* Provides a fake implementations of {@link LocaleInfoImpl} that makes use of
* {@link DefaultDateTimeFormatInfo}, which makes date/time formatting possible in tests.
*
* @author ekuefler@google.com (Erik Kuefler)
*/
public class FakeLocaleInfoImplProvider implements FakeProvider<LocaleInfoImpl> {
@Override
public LocaleInfoImpl getFake(Class<?> type) {
return new LocaleInfoImpl() {
@Override
public DateTimeFormatInfo getDateTimeFormatInfo() {
return new DefaultDateTimeFormatInfo();
}
};
}
}
10 changes: 10 additions & 0 deletions gwtmockito/src/test/java/com/google/gwtmockito/GwtMockitoTest.java
Expand Up @@ -34,6 +34,7 @@
import com.google.gwt.dom.client.IFrameElement;
import com.google.gwt.dom.client.Node;
import com.google.gwt.i18n.client.BidiPolicy;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.i18n.client.Messages;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
Expand Down Expand Up @@ -74,6 +75,8 @@
import org.mockito.Matchers;
import org.mockito.Mock;

import java.util.Date;

/**
* Tests for {@link GwtMockito} when running with {@link GwtMockitoTestRunner}.
*/
Expand Down Expand Up @@ -561,6 +564,13 @@ public void render(Context context, String value, SafeHtmlBuilder sb) {}
}));
}

@Test
@SuppressWarnings("deprecation")
public void shouldBeAbleToFormatDatesWithAmPm() {
DateTimeFormat formatter = DateTimeFormat.getFormat("yyyy/MM/dd hh:mm:ss a");
assertEquals("1992/11/09 12:34:56 PM", formatter.format(new Date(92, 10, 9, 12, 34, 56)));
}

static class PackagePrivateClass {
String doStuff() {
return "not mocked";
Expand Down

0 comments on commit c5465ca

Please sign in to comment.