+++ /dev/null
-/*
- * 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();
-}
+++ /dev/null
-/*
- * 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();
- }
-}
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;
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);
}
/**
}
private Date now() {
- return dateProvider.now();
+ return new Date(system.now());
}
}
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;
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
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);