]> source.dussan.org Git - sonarqube.git/commitdiff
Replace package org.sonar.core.date by org.sonar.api.util.System2
authorSimon Brandhof <simon.brandhof@gmail.com>
Sat, 11 Jan 2014 13:22:45 +0000 (14:22 +0100)
committerSimon Brandhof <simon.brandhof@gmail.com>
Sat, 11 Jan 2014 13:22:45 +0000 (14:22 +0100)
sonar-core/src/main/java/org/sonar/core/date/DateProvider.java [deleted file]
sonar-core/src/main/java/org/sonar/core/date/DefaultDateProvider.java [deleted file]
sonar-core/src/main/java/org/sonar/core/permission/PermissionTemplateDao.java
sonar-core/src/test/java/org/sonar/core/permission/PermissionTemplateDaoTest.java

diff --git a/sonar-core/src/main/java/org/sonar/core/date/DateProvider.java b/sonar-core/src/main/java/org/sonar/core/date/DateProvider.java
deleted file mode 100644 (file)
index f6fd58f..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.core.date;
-
-import java.util.Date;
-
-/**
- * @since 3.7
- */
-public interface DateProvider {
-
-  Date now();
-}
diff --git a/sonar-core/src/main/java/org/sonar/core/date/DefaultDateProvider.java b/sonar-core/src/main/java/org/sonar/core/date/DefaultDateProvider.java
deleted file mode 100644 (file)
index eb716b2..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-
-package org.sonar.core.date;
-
-import java.util.Date;
-
-public class DefaultDateProvider implements DateProvider {
-
-  @Override
-  public Date now() {
-    return new Date();
-  }
-}
index 8ae2506a55148fd0891ba5d918b123d9532dad67..6ae3e5214785c515b01dc3211bacbca5c75cf1bc 100644 (file)
@@ -27,8 +27,7 @@ import org.apache.ibatis.session.SqlSession;
 import org.sonar.api.ServerComponent;
 import org.sonar.api.security.DefaultGroups;
 import org.sonar.api.task.TaskComponent;
-import org.sonar.core.date.DateProvider;
-import org.sonar.core.date.DefaultDateProvider;
+import org.sonar.api.utils.System2;
 import org.sonar.core.persistence.MyBatis;
 
 import javax.annotation.CheckForNull;
@@ -45,15 +44,15 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent {
   public static final String QUERY_PARAMETER = "query";
   public static final String TEMPLATE_ID_PARAMETER = "templateId";
   private final MyBatis myBatis;
-  private final DateProvider dateProvider;
+  private final System2 system;
 
-  public PermissionTemplateDao(MyBatis myBatis, DateProvider dateProvider) {
+  PermissionTemplateDao(MyBatis myBatis, System2 system) {
     this.myBatis = myBatis;
-    this.dateProvider = dateProvider;
+    this.system = system;
   }
 
   public PermissionTemplateDao(MyBatis myBatis) {
-    this(myBatis, new DefaultDateProvider());
+    this(myBatis, System2.INSTANCE);
   }
 
   /**
@@ -258,6 +257,6 @@ public class PermissionTemplateDao implements TaskComponent, ServerComponent {
   }
 
   private Date now() {
-    return dateProvider.now();
+    return new Date(system.now());
   }
 }
index 53daae1c5643d3aa8e52b9c6ba38f09c4b64a1e7..23070b147cca1107e9d9b9c801a764846b347e5c 100644 (file)
@@ -23,7 +23,7 @@ package org.sonar.core.permission;
 import org.apache.ibatis.session.SqlSession;
 import org.junit.Before;
 import org.junit.Test;
-import org.sonar.core.date.DateProvider;
+import org.sonar.api.utils.System2;
 import org.sonar.core.persistence.AbstractDaoTestCase;
 import org.sonar.core.persistence.MyBatis;
 
@@ -39,14 +39,13 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
 
   Date now;
   PermissionTemplateDao permissionTemplateDao;
-  DateProvider dateProvider;
+  System2 system = mock(System2.class);
 
   @Before
   public void setUpDao() throws ParseException {
     now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2013-01-02 01:04:05");
-    dateProvider = mock(DateProvider.class);
-    stub(dateProvider.now()).toReturn(now);
-    permissionTemplateDao = new PermissionTemplateDao(getMyBatis(), dateProvider);
+    when(system.now()).thenReturn(now.getTime());
+    permissionTemplateDao = new PermissionTemplateDao(getMyBatis(), system);
   }
 
   @Test
@@ -78,7 +77,7 @@ public class PermissionTemplateDaoTest extends AbstractDaoTestCase {
     MyBatis myBatis = mock(MyBatis.class);
     when(myBatis.openSession()).thenReturn(session);
 
-    permissionTemplateDao = new PermissionTemplateDao(myBatis, dateProvider);
+    permissionTemplateDao = new PermissionTemplateDao(myBatis, system);
     PermissionTemplateDto permissionTemplate = permissionTemplateDao.createPermissionTemplate(PermissionTemplateDto.DEFAULT.getName(), null, null);
 
     verify(mapper).insert(permissionTemplate);